gulp的watch记事本

let gulp=require('gulp'),
	nodemon=require('gulp-nodemon'),
	browser=require('browser-sync');
let reload=browser.reload;
gulp.task('serve',function(){
	browser.init({
		proxy:'http://localhost:3000',
		notify:false,
		port:3001
	});
	gulp.watch(["./views/*.pug","./views/**/*.pug","!./views/layout.pug"]).on('change',reload);
});
gulp.task('start',function(){
	nodemon({
		script:'app.js',
		ext:'js html',
		env:{'NODE_ENV':'development'}
	});
});
gulp.task('default',['start','serve']);

通过!排除不需要监听的文件。

一下来自官方文档API页面: http://www.gulpjs.com.cn/docs/api/
gulp.watch(glob[, opts], tasks)
glob
类型: String or Array
一个 glob 字符串,或者一个包含多个 glob 字符串的数组,用来指定具体监控哪些文件的变动。

posted @ 2017-07-07 17:37  海客无心x  阅读(179)  评论(0编辑  收藏  举报