0
我的目錄結構如下:一飲而盡,注入不能注入js文件中的index.html
|- 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
);
});
我的指數.html文件如下所示:
<!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文件沒有通過gulp添加到index.html中。那麼路徑有什麼問題嗎?
它增加了** **而不是** ** –
嘗試'var sources = gulp.src(['./ app/js/**/*。js'] ,{read:false},{relative:true});'ref:https://github.com/klei/gulp-inject/wiki/Clarifying-injected-paths – dCrux
我試過了你的代碼。有效! –