[英]Gulp watch doesn't finished
var gulp = require('gulp');
var livereload = require('gulp-livereload');
var uglify = require('gulp-uglifyjs');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
gulp.task('imagemin', function() {
return gulp.src('./themes/custom/sebastian/images/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{ removeViewBox: false }],
use: [pngquant()]
}))
.pipe(gulp.dest('./themes/custom/sebastian/images'));
});
gulp.task('sass', function() {
return gulp.src('./themes/custom/sebastian/sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 7', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./themes/custom/sebastian/css'));
});
gulp.task('uglify', function() {
return gulp.src('./themes/custom/sebastian/lib/*.js')
.pipe(uglify('main.js'))
.pipe(gulp.dest('./themes/custom/sebastian/js'));
});
gulp.task('watch', function() {
livereload.listen();
gulp.watch('./themes/custom/sebastian/sass/**/*.scss', gulp.series('sass'));
gulp.watch('./themes/custom/sebastian/lib/*.js', gulp.series('uglify'));
gulp.watch(
[
'./themes/custom/sebastian/css/style.css',
'./themes/custom/sebastian/**/*.twig',
'./themes/custom/sebastian/js/*.js'
],
function(files) {
livereload.changed(files);
}
);
});
[18:40:58] 使用 gulpfile C:\xampp\htdocs\drupal-8.7.9\drupal-8.7.9\themes\custom\sebastian\gulpfile.js
[18:40:58] 开始“观看”...
为什么手表不走完?
Gulp 手表不会在 sebastian 文件夹中创建 css 文件夹。
watch
任务没有完成,因为您没有终止该任务 - 就像您在其他任务中使用return
语句所做的那样。 但这是一件好事。
您不希望watch
任务终止 - 您希望它在编辑文件时继续监视文件,然后watch
任务将触发其他任务。
watch
任务本身 - 就像第一次运行一样 - 不会触发sass
任务,直到您编辑它正在监视的.scss
文件。 执行此操作后,应立即触发sass
任务并创建 output .ZC7A62 .css
文件。
如果这确实是您想要的,可以选择在第一次运行时触发watch
任务。 但这听起来不像是你的问题。
gulp.task('watch', function(callback) {
livereload.listen();
gulp.watch('./themes/custom/sebastian/sass/**/*.scss', gulp.series('sass'));
gulp.watch('./themes/custom/sebastian/lib/*.js', gulp.series('uglify'));
gulp.watch(
[
'./themes/custom/sebastian/css/style.css',
'./themes/custom/sebastian/**/*.twig',
'./themes/custom/sebastian/js/*.js'
],
function(files) {
livereload.changed(files);
}
);
callback()
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.