首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gulp监视在文件更改时不触发minify

Gulp监视在文件更改时不触发minify
EN

Stack Overflow用户
提问于 2019-11-25 05:27:54
回答 1查看 78关注 0票数 0

我有一个简单的入门应用程序,我创建了gulpfile.js文件的内容如下,

代码语言:javascript
复制
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:

代码语言:javascript
复制
..
     "gulp": "^4.0.2",
     "gulp-clean-css": "^4.2.0"
EN

回答 1

Stack Overflow用户

发布于 2019-11-26 15:08:56

我认为您需要在运行任务minify-css时添加return,以便系统知道前一个任务何时完成。

代码语言:javascript
复制
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');
  });
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59022589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档