【问题标题】:Glob watch multiple files, process oneGlob 监视多个文件,处理一个
【发布时间】:2019-04-12 06:33:39
【问题描述】:

我使用Gulp 4gulp-sass。我尝试做的是以下内容。

  • 我在这里提供的代码只是整个代码的一个片段,用于展示重要部分。
  • watch 应该喜欢它,查看所有.scss 文件。
  • style() 中,只会处理当前文件。
  • 如果我保存custom/components/header/header.scss,那么应该只处理custom/components/header/header.scss,而不是所有文件。
  • 保存的文件应该有一个类似assets/css/dist/header/header.css的文件名
  • 在这种情况下,srcdest 都是未知的,因为我没有一个文件可以抓取。
  • 我现在看到我还需要从dest 中删除custom/components,但重要的是我可以让当前文件开始使用它。
gulp.watch('custom/components/**/*.scss', style);
function style() {
  return gulp
    .src()
    .pipe(sass())
    .on('error', sass.logError)
    .pipe(gulp.dest('assets/css/dist'));
}

【问题讨论】:

    标签: gulp gulp-sass gulp-dest


    【解决方案1】:

    我只是想通了。可以这样做。

    let watcher = gulp.watch(css.watch);
    
    watcher.on('change', function(path) {
      console.log(path);
      style();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-24
      • 2019-06-06
      • 1970-01-01
      相关资源
      最近更新 更多