我有一个简单的入门应用程序,我创建了gulpfile.js文件,其内容如下,
let gulp = require('gulp');
let cleanCSS = require('gulp-clean-css');
// Task to minify css using package cleanCSs
gulp.task('minify-css', () => {
// Folder with files to minify
return gulp.src('src/assets/styles/*.css')
//The method pipe() allow you to chain multiple tasks together
//I execute the task to minify the files
.pipe(cleanCSS())
//I define the destination of the minified files with the method dest
.pipe(gulp.dest('src/assets/dist'));
});
//We create a 'default' task that will run when we run `gulp` in the project
gulp.task('default', function() {
// We use `gulp.watch` for Gulp to expect changes in the files to run again
gulp.watch('./src/assets/styles/*.css', function(evt) {
gulp.task('minify-css');
});
});
如果运行gulp minify-css
,它可以正常工作,但是我需要它来减小文件更改的大小
但是所有的操作都会在cmd窗口中记录一条消息,例如'Starting ...'
我什至不知道这是什么意思...
package.json:
..
"gulp": "^4.0.2",
"gulp-clean-css": "^4.2.0"
我认为您在运行任务minify-css时需要添加return,以便系统知道上一个任务何时完成。
gulp.task('default', function() {
// We use `gulp.watch` for Gulp to expect changes in the files to run again
gulp.watch('./src/assets/styles/*.css', function(evt) {
return gulp.task('minify-css');
});
});