我项目中使用gulp-changed插件,但是在用的过程中,我改变一个文件会触发所有文件的重新编译,gulp-changed并没有起到过滤的作用。
var objectPath = {
// 开发环境
dev: {
css: 's/2017/src/css/*.css',
js: 's/2017/src/js/*.js',
img: 's/2017/src/image/*',
html: 'App/Tpl/Home/Index/Test'
},
// 发布环境
dist: {
css: 's/2017/dist/',
img: 's/2017/dist/',
js: 's/2017/dist/'
}
};
gulp.task('cssmin', ()=> {
gulp.src(objectPath.dev.css, {base: 's/2017/src/'})
.pipe(plugin.changed(objectPath.dist.css))// 过滤修改过的文件,src与dist进行对比
.pipe(plugin.debug({title:'unicorn'}))
.pipe(plugin.plumber({errorHandler: plugin.notify.onError("Error: <%= error.message %>")}))// 捕获错误信息
.pipe(plugin.autoprefixer({
browsers: ['last 2 versions'],
cascade: true
}))
.pipe(plugin.csslint())
.pipe(plugin.cleanCss({
compatibility: 'ie8',// 兼容ie8+
advanced: false,// 关闭高级优化
keepSpecialComments: '*'// //保留所有特殊前缀 当你用autoprefixer生成的浏览器前缀,如果不加这个参数,有可能将会删除你的部分前缀
}))
.pipe(plugin.rename({
suffix: '.min'// 后缀拼接
}))
.pipe(gulp.dest(objectPath.dist.css))
.pipe(plugin.livereload());// 自动刷新
});