【问题标题】:Watch for changes in subdirectories but target a single file as src in Gulp注意子目录中的更改,但在 Gulp 中将单个文件定位为 src
【发布时间】:2017-11-27 21:00:13
【问题描述】:

我有以下 gulp 任务:

gulp.task("stylePipe", function(){

  var postcssPlugins = [
    autoprefixer({browsers: ['last 2 version']}), // autoprefixer
    cssnano() // css minifier
  ];

  gulp.src("src/sass/*.scss") 
  .pipe(sourcemaps.init())
  .pipe(plumber())
  .pipe(sass().on("error", sass.logError)) // scan for errors
  .pipe(postcss(postcssPlugins)) // runs postcss plugins listed above
  .pipe(rename({ extname: '.min.css' }))
  .pipe(sourcemaps.write('maps'))
  .pipe(gulp.dest("dist/css")); // compile into dist

});

gulp.task("styleWatch", ["stylePipe"], browsersync.reload);

gulp.task("watch", function(){

  browsersync({
    server: {
      baseDir: "dist/"
    }
  });

  gulp.watch("src/sass/*.scss", ["styleWatch"]);
});

我想观察下面列出的所有子目录的变化

将 main.scss 用作 gulp.src("src/sass/*.scss") 中的 src(只要有更改子目录的文件)。

我怎样才能做到这一点?

【问题讨论】:

    标签: gulp gulp-watch gulp-sass


    【解决方案1】:

    我只是修改了

      gulp.watch("src/sass/*.scss", ["styleWatch"]);
    

    进入

      gulp.watch("src/sass/**/*.scss", ["styleWatch"]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-21
      • 2017-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多