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 watch不会在sebastian文件夹中创建一个css文件夹。
答案 0 :(得分:0)
watch
任务没有完成,因为您没有终止该任务-就像您在其他任务中使用return
语句那样。 但这是一件好事。
您不希望watch
任务终止-您希望它在编辑文件时一直监视文件,然后watch
任务将触发其他任务。
像您第一次运行一样,watch
任务本身不会触发sass
任务,除非您编辑正在监视的.scss
文件。完成此操作后,应立即触发sass
任务并创建输出.css
文件。
如果您确实希望这么做,则可以选择在初次运行时触发watch
任务。但这听起来不像是您的问题。
答案 1 :(得分:0)
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()
});