gulp-inject 不适用于事件流。
var gulp = require('gulp');
var mainBowerFiles = require('main-bower-files');
var inject = require('gulp-inject');
var es = require('event-stream');
var config = {
sassDir: './resources/assets/sass',
jsPath: './resources/app',
fontDir: './resources/fonts',
imageDir: './resources/images',
bowerDir: './bower_components'
};
gulp.task('index', function () {
return gulp.src('./resources/index.html')
.pipe(inject(gulp.src(mainBowerFiles('**/*.js'), {read: false}), {name: 'bower'}))
.pipe(inject(es.merge(gulp.src(config.jsPath + '/**/*.js', {read: false}))))
.pipe(gulp.dest('./public'));
});
结果是这样来的。
<!-- inject:js -->
<script src="/resources/app/core.js"></script>
<script src="/resources/app/first-folder/01.js"></script>
<script src="/resources/app/second-folder/02.js"></script>
<!-- endinject -->
不幸的是,mainBowerFiles('**/*.js')
不要合并inject(es.merge(gulp.src(config.jsPath + '/**/*.js', {read: false})))