使用Gulp&使用'gulp.watch'的Gulp-sass,如何在监视列表中返回已更改项目的目录名,以便我可以将sass编译为css?
这就是我现在拥有它的方式;正如您所看到的,只有一个目录被编译为主题1.如果主题2或3在SASS中发生更改,则主题1 css将会更新。我希望它是有条件的,所以要么根据不同的变化而改变。
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('sass', function () {
return gulp.src('./wp-content/themes/1/assets/sass/**/*.scss')
.pipe(sass.sync().on('error', sass.logError))
.pipe(gulp.dest('./wp-content/themes/1/'));
});
gulp.task('sass:watch', function () {
gulp.watch('./wp-content/themes/1/assets/sass/**/*.scss', ['sass']);
gulp.watch('./wp-content/themes/2/assets/sass/**/*.scss', ['sass']);
gulp.watch('./wp-content/themes/3/assets/sass/**/*.scss', ['sass']);
});
答案 0 :(得分:0)
虽然这是非常硬编码的,但这是我刚刚找到的解决方案。
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('sass', function () {
// return gulp.src('./wp-content/themes/giggleselc/assets/sass/**/*.scss')
// .pipe(sass.sync().on('error', sass.logError))
// .pipe(gulp.dest('./wp-content/themes/giggleselc/'));
});
gulp.task('sass:watch', function () {
var n1 = gulp.watch('./wp-content/themes/1/assets/sass/**/*.scss', ['sass']);
var n2 = gulp.watch('./wp-content/themes/2/assets/sass/**/*.scss', ['sass']);
var n3 = gulp.watch('./wp-content/themes/3/assets/sass/**/*.scss', ['sass']);
n1.on('change', function(f) {
return gulp.src('./wp-content/themes/1/assets/sass/**/*.scss')
.pipe(sass.sync().on('error', sass.logError))
.pipe(gulp.dest('./wp-content/themes/1/'));
});
n2.on('change', function(f) {
console.log('Change Event:', f);
return gulp.src('./wp-content/themes/2/assets/sass/**/*.scss')
.pipe(sass.sync().on('error', sass.logError))
.pipe(gulp.dest('./wp-content/themes/2/'));
});
n3.on('change', function(f) {
return gulp.src('./wp-content/themes/3/assets/sass/**/*.scss')
.pipe(sass.sync().on('error', sass.logError))
.pipe(gulp.dest('./wp-content/themes/3/'));
});
});