我的目录结构如下:
|- 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
);
});我的index.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中。那么路径有什么问题吗?
发布于 2017-07-31 23:04:11
尝试将var inject = require('gulp-inject');和var gulp = require('gulp');添加到插入文件的顶部。
然后再看看你的源代码和gulp.dest:
var sources = gulp.src(['./app/js/**/*.js'], { read: false });
您需要在应用程序之前使用proceed ./。
编辑:
使用relative true处理注入目录树中较高位置文件夹中的文件
var sources = gulp.src(['./app/js/**/*.js'], { read: false }, {relative: true});
https://stackoverflow.com/questions/45409878
复制相似问题