2017-07-31 6 views
0

次のように私のディレクトリ構造は次のとおりです。以下に示すように一息-注入はindex.htmlの中のjsファイルを注入することができません

|- app 
    |- bower_components 
    |- css 
    |- img 
    |- js 
    |- scss 
    |- template 
|- node_modules 
|- gulpfile.js 
|- package.json 
|- .bowerrc 
|- bower.json 

今私のgulpfile.jsは次のとおりです。

gulp.task('index', function() { 
    var target = gulp.src('./app/index.html'); 
    var sources = gulp.src(['app/js/**/*.js'], { read: false }); 

    return target.pipe(inject(sources)) 
     .pipe(gulp.dest('app/js')); 
}); 


gulp.task('default', function(callback) { 
    runSequence(['sass', 'browserSync', 'index'], 'watch', 
     callback 
    ); 
}); 

マイ指数一息経由

<!DOCTYPE html> 
<html> 

<head> 
    <title>kisanApp</title> 
    <!-- inject:css --> 
    <!-- endinject --> 
</head> 

<body ng-app="kisanApp"> 
    <ng-view></ng-view> 
    <!-- inject:js --> 
    <!-- endinject --> 
    <script src="bower_components/angular/angular.js"></script> 
    <script src="bower_components/angular-route/angular-route.js"></script> 
</body> 

</html> 

しかし、どういうわけか、私のjsファイルはindex.htmlの中に追加されません:.htmlのファイルは、以下の通りです。パスに何か問題がありますか?

答えて

1

var inject = require('gulp-inject');var gulp = require('gulp');をgulpfileの先頭に追加してください。その後、

そして、あなたのソースで別のを見て、gulp.dest:

var sources = gulp.src(['./app/js/**/*.js'], { read: false });

あなたはアプリの前に./を進める必要があるでしょう。

EDIT:

使用relative trueフォルダから注入ファイルを扱うためのディレクトリツリーでは、最大高

var sources = gulp.src(['./app/js/**/*.js'], { read: false }, {relative: true});

+0

それ追加** <スクリプトSRC = "/アプリ/ JS/app.js "> ** ** ** –

+1

ではなく、var sources = gulp.src(['。/ app/js/**/*。js'] {ref:false}、{relative:true}); ref:https://github.com/klei/gulp-inject/wiki/Clarifying-injected-paths – dCrux

+0

あなたのコードを試しました。出来た! –

関連する問題