gulp-观看无休止的编译而不对文件进行更改
gulp-watch endlessly compiling without changes being made to files
出于某种原因,我的脚本 gulp-watch 任务无休止地循环运行(以至于它激活了我的 MBP 上的风扇!),尽管我使用的是相同的 gulp 文件在其他各种项目中。
它只是一遍又一遍地编译脚本。尝试删除所有节点模块并再次使用 npm install
。但同样的问题。我设置的 sass 编译任务没有同样的问题。
我什至尝试排除编译供应商代码,如 jquery/其他插件。 gulp.watch(['./js/*.js', '!./js/vendor/**'], ['scripts']);
但仍然有同样的问题。
也试着把一些脚本注释掉,然后一一重新介绍。但是似乎没有一个一致的违规脚本。
// include gulp
var gulp = require('gulp');
// --------------------------------------------------------------
// Plugins
// ---------------------------------------------------------------
var concat = require('gulp-concat');
var stripDebug = require('gulp-strip-debug');
var uglify = require('gulp-uglify');
var include = require('gulp-include');
var sass = require('gulp-sass');
var minifycss = require('gulp-minify-css');
var watch = require('gulp-watch');
var livereload = require('gulp-livereload');
var changed = require('gulp-changed');
// --------------------------------------------------------------
// JS
// ---------------------------------------------------------------
gulp.task('scripts', function() {
gulp.src(['./js/script.js'])
.pipe(include())
.pipe(concat('script-dist.js'))
.pipe(stripDebug())
.pipe(uglify())
.pipe(gulp.dest('./js/'))
.pipe(livereload());
});
// --------------------------------------------------------------
// Sass
// ---------------------------------------------------------------
gulp.task('styles', function() {
gulp.src('./ui/scss/styles.scss')
.pipe(include())
.pipe(sass({
errLogToConsole: true
}))
.pipe(minifycss())
.pipe(gulp.dest('./ui/css/'))
.pipe(livereload());
});
gulp.task('watch', function() {
gulp.watch('./ui/scss/*.scss', ['styles']);
gulp.watch('./js/*.js', ['scripts']);});
gulp.task('default', ['styles', 'watch']);
gulp.task('default', ['scripts', 'watch']);
livereload.listen();
终端输出(路径替换为'PATH'):
[15:49:17] Starting 'scripts'...
[15:49:17] Finished 'scripts' after 2.08 ms
[15:49:18] /_PATH_//js/script-dist.js reloaded.
[15:49:18] Starting 'scripts'...
[15:49:18] Finished 'scripts' after 2.58 ms
[15:49:19] /_PATH_//js/script-dist.js reloaded.
[15:49:19] Starting 'scripts'...
[15:49:19] Finished 'scripts' after 1.41 ms
[15:49:19] /_PATH_//js/script-dist.js reloaded.
[15:49:30] Starting 'scripts'...
[15:49:30] Finished 'scripts' after 1.42 ms
[15:49:31] /_PATH_//js/script-dist.js reloaded.
[15:49:31] Starting 'scripts'...
[15:49:31] Finished 'scripts' after 2.45 ms
[15:49:32] /_PATH_//js/script-dist.js reloaded.
[15:49:32] Starting 'scripts'...
[15:49:32] Finished 'scripts' after 1.17 ms
[15:49:33] /_PATH_//js/script-dist.js reloaded.
[15:49:33] Starting 'scripts'...
[15:49:33] Finished 'scripts' after 1.84 ms
[15:49:34] Starting 'scripts'...
[15:49:34] Finished 'scripts' after 1.1 ms
[15:49:35] /_PATH_//js/script-dist.js reloaded.
[15:49:35] Starting 'scripts'...
[15:49:35] Finished 'scripts' after 1.73 ms
[15:49:36] Starting 'scripts'...
[15:49:36] Finished 'scripts' after 1.12 ms
[15:49:36] /_PATH_//js/script-dist.js reloaded.
[15:49:36] /_PATH_//js/script-dist.js reloaded.
[15:49:36] Starting 'scripts'...
[15:49:36] Finished 'scripts' after 908 μs
[15:49:37] /_PATH_//js/script-dist.js reloaded.
[15:49:37] /_PATH_//js/script-dist.js reloaded.
您正在观看 js
文件夹中的 *.js
个文件,然后是 运行 scripts
任务。
gulp.watch('./js/*.js', ['scripts']);});
您的 scripts
任务是将 .js
文件写入 js
文件夹
.pipe(gulp.dest('./js/'))
...然后再次触发监视条件....您现在有一个循环。
出于某种原因,我的脚本 gulp-watch 任务无休止地循环运行(以至于它激活了我的 MBP 上的风扇!),尽管我使用的是相同的 gulp 文件在其他各种项目中。
它只是一遍又一遍地编译脚本。尝试删除所有节点模块并再次使用 npm install
。但同样的问题。我设置的 sass 编译任务没有同样的问题。
我什至尝试排除编译供应商代码,如 jquery/其他插件。 gulp.watch(['./js/*.js', '!./js/vendor/**'], ['scripts']);
但仍然有同样的问题。
也试着把一些脚本注释掉,然后一一重新介绍。但是似乎没有一个一致的违规脚本。
// include gulp
var gulp = require('gulp');
// --------------------------------------------------------------
// Plugins
// ---------------------------------------------------------------
var concat = require('gulp-concat');
var stripDebug = require('gulp-strip-debug');
var uglify = require('gulp-uglify');
var include = require('gulp-include');
var sass = require('gulp-sass');
var minifycss = require('gulp-minify-css');
var watch = require('gulp-watch');
var livereload = require('gulp-livereload');
var changed = require('gulp-changed');
// --------------------------------------------------------------
// JS
// ---------------------------------------------------------------
gulp.task('scripts', function() {
gulp.src(['./js/script.js'])
.pipe(include())
.pipe(concat('script-dist.js'))
.pipe(stripDebug())
.pipe(uglify())
.pipe(gulp.dest('./js/'))
.pipe(livereload());
});
// --------------------------------------------------------------
// Sass
// ---------------------------------------------------------------
gulp.task('styles', function() {
gulp.src('./ui/scss/styles.scss')
.pipe(include())
.pipe(sass({
errLogToConsole: true
}))
.pipe(minifycss())
.pipe(gulp.dest('./ui/css/'))
.pipe(livereload());
});
gulp.task('watch', function() {
gulp.watch('./ui/scss/*.scss', ['styles']);
gulp.watch('./js/*.js', ['scripts']);});
gulp.task('default', ['styles', 'watch']);
gulp.task('default', ['scripts', 'watch']);
livereload.listen();
终端输出(路径替换为'PATH'):
[15:49:17] Starting 'scripts'...
[15:49:17] Finished 'scripts' after 2.08 ms
[15:49:18] /_PATH_//js/script-dist.js reloaded.
[15:49:18] Starting 'scripts'...
[15:49:18] Finished 'scripts' after 2.58 ms
[15:49:19] /_PATH_//js/script-dist.js reloaded.
[15:49:19] Starting 'scripts'...
[15:49:19] Finished 'scripts' after 1.41 ms
[15:49:19] /_PATH_//js/script-dist.js reloaded.
[15:49:30] Starting 'scripts'...
[15:49:30] Finished 'scripts' after 1.42 ms
[15:49:31] /_PATH_//js/script-dist.js reloaded.
[15:49:31] Starting 'scripts'...
[15:49:31] Finished 'scripts' after 2.45 ms
[15:49:32] /_PATH_//js/script-dist.js reloaded.
[15:49:32] Starting 'scripts'...
[15:49:32] Finished 'scripts' after 1.17 ms
[15:49:33] /_PATH_//js/script-dist.js reloaded.
[15:49:33] Starting 'scripts'...
[15:49:33] Finished 'scripts' after 1.84 ms
[15:49:34] Starting 'scripts'...
[15:49:34] Finished 'scripts' after 1.1 ms
[15:49:35] /_PATH_//js/script-dist.js reloaded.
[15:49:35] Starting 'scripts'...
[15:49:35] Finished 'scripts' after 1.73 ms
[15:49:36] Starting 'scripts'...
[15:49:36] Finished 'scripts' after 1.12 ms
[15:49:36] /_PATH_//js/script-dist.js reloaded.
[15:49:36] /_PATH_//js/script-dist.js reloaded.
[15:49:36] Starting 'scripts'...
[15:49:36] Finished 'scripts' after 908 μs
[15:49:37] /_PATH_//js/script-dist.js reloaded.
[15:49:37] /_PATH_//js/script-dist.js reloaded.
您正在观看 js
文件夹中的 *.js
个文件,然后是 运行 scripts
任务。
gulp.watch('./js/*.js', ['scripts']);});
您的 scripts
任务是将 .js
文件写入 js
文件夹
.pipe(gulp.dest('./js/'))
...然后再次触发监视条件....您现在有一个循环。