这是一个完整的gulp js文件。这里没有使用gulp-watch
。所以它的评论。
gulp.task('scripts', function() {
gulp.src(['app/*.js', 'app/shared/*/*.js','app/components/*/*.js'])
.pipe(plumber({
handleError: function(err) {
console.log(err);
this.emit('end');
}
}))
// .pipe(watch(['app/*.js', 'app/shared/*/*.js','app/components/*/*.js']))
.pipe(print(function(filepath) {
return "MrGopal modified : " + filepath;
}))
.pipe(ngAnnotate())
.pipe(concate('zaya.app.js'))
.pipe(rename({
suffix: '.min'
}))
.pipe(uglify())
.pipe(gulp.dest('assets/js'))
.pipe(broswerSync.stream())
})
浏览器同步任务
gulp.task('browser-sync', function() {
broswerSync.init({
notify: true,
proxy: "http://localhost:8000"
})
})
gulp.task('scripts-sync',['scripts'],broswerSync.reload)
gulp.task('html-sync',['html'],broswerSync.reload)
gulp.task('less-sync',['less'],broswerSync.reload)
观看任务
gulp.watch(['app/*.js', 'app/shared/*/*.js', 'app/components/*/*.js'], ['scripts','scripts-sync']);
gulp.watch(['app/shared/*/*.html','app/components/*/*.html'], ['html','html-sync']);
gulp.watch(['app/shared/*/*.css','app/components/*/*.css'], ['less','less-sync']);
DEFAULT TASK
gulp.task('default', ['scripts', 'html', 'less', 'watch','browser-sync'])
虽然运行gulp,但它表示手表不是功能。但同样的代码在我的办公室工作。可能有什么不对?
错误代码:
[16:03:49] 'watch' errored after 244 μs
[16:03:49] TypeError: undefined is not a function
at Gulp.watch (/home/gopal/Documents/zaya-proto/zaya/zaya/static/node_modules/gulp/index.js:35:16)
at Gulp.<anonymous> (/home/gopal/Documents/zaya-proto/zaya/zaya/static/gulpfile.js:96:10)
at module.exports (/home/gopal/Documents/zaya-proto/zaya/zaya/static/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/home/gopal/Documents/zaya-proto/zaya/zaya/static/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/home/gopal/Documents/zaya-proto/zaya/zaya/static/node_modules/orchestrator/index.js:214:10)
at /home/gopal/Documents/zaya-proto/zaya/zaya/static/node_modules/orchestrator/index.js:279:18
at finish (/home/gopal/Documents/zaya-proto/zaya/zaya/static/node_modules/orchestrator/lib/runTask.js:21:8)
at module.exports (/home/gopal/Documents/zaya-proto/zaya/zaya/static/node_modules/orchestrator/lib/runTask.js:60:3)
at Gulp.Orchestrator._runTask (/home/gopal/Documents/zaya-proto/zaya/zaya/static/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/home/gopal/Documents/zaya-proto/zaya/zaya/static/node_modules/orchestrator/index.js:214:10)