首先,安装gulp,gulp-clean-css并gulp-rename在本地项目目录中
npm install --save-dev gulp gulp-clean-css gulp-rename
比将以下minify-css任务添加到您的gulpfile.js
var gulp = require('gulp'); var cleanCSS = require('gulp-clean-css'); var rename = require('gulp-rename'); gulp.task('minify-css', function() { return gulp.src('css/dist/dist.css') .pipe(cleanCSS()) .pipe(rename('dist.min.css')) .pipe(gulp.dest('css/dist')); }); gulp.task('watch', function(){ gulp.watch('css/dist/**/*.css', ['minify-css']); // 其他观察者 }); gulp.task('default', ['minify-css', 'watch']);
在这里执行文件的缩小并将其重命名为.pipe(cleanCSS())css/dist/dist.css.pipe(rename('concat.min.css'))dist.min.css