我正在尝试使用gulp-watch和gulp-inject来构建我的Node Web应用程序 . 但是,一旦gulp-watch参与其中,似乎涉及gulp-inject的构建步骤将无效 . 貌似,the reason is that the watch stream never ends and gulp-inject doesn't know when to start .
我的gulpfile看起来如下:
var gulp = require('gulp')
var inject = require('gulp-inject')
var sass = require('gulp-sass')
var path = require('path')
var bower = require('gulp-bower')
var bowerFiles = require('main-bower-files')
var react = require('gulp-react')
var watch = require('gulp-watch')
var plumber = require('gulp-plumber')
var bowerDir = './bower_components/'
gulp.task('bower', function () {
return bower()
})
gulp.task('default', function () {
var css = watch('./stylesheets/*.scss')
.pipe(plumber())
.pipe(sass({
includePaths: [
bowerDir + 'bootstrap-sass-official/assets/stylesheets',
]
}))
.pipe(gulp.dest('./public/css'))
var jsxFiles = watch(['./jsx/about.js', './jsx/home.js', './jsx/app.js'])
.pipe(plumber())
.pipe(react())
.pipe(gulp.dest('./public/js'))
var bowerJs = gulp.src(bowerFiles(), {read: false})
watch('./views/index.html')
.pipe(plumber())
// Does not produce output - presumably because watch source hasn't ended its stream
.pipe(inject(css))
.pipe(inject(bowerJs, {name: 'bower'}))
.pipe(inject(jsxFiles, {name: 'jsx'}))
.pipe(gulp.dest('./public/html'))
})
我怎样才能成功地结合gulp-watch和gulp-inject?
你可以在GitHub上看到我的完整项目 .
2 回答
我最终解决了这个问题,不在流中包含gulp-watch,而是创建一个单独的“监视”任务,当源更改时触发构建 . 我仍然想知道是否有办法使我的原始方法工作 .
希望你可以在想要使用时编写单独的gulp-inject功能 .
甚至你可以使用函数内部的参数 .
调用函数:
inject()