我已经定义了这个Gulp配置:
var gulp = require('gulp'),
minify = require('gulp-minify-css'),
sourcemaps = require('gulp-sourcemaps'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
notify = require('gulp-notify'),
livereload = require('gulp-livereload');
gulp.task('default', ['css', 'js', 'watch']);
gulp.task('watch', function () {
livereload.listen();
gulp.watch('src/AppBundle/Resources/public/css/*.css', ['css']);
gulp.watch('src/AppBundle/Resources/public/js/**/*.js', ['js']);
});
gulp.task('css', function () {
gulp.src('src/AppBundle/Resources/public/css/*.css')
.pipe(sourcemaps.init())
.pipe(minify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('src/AppBundle/Resources/public/css/min'))
.pipe(livereload());
});
gulp.task('js', function () {
return gulp.src('src/Sencamer/Resources/public/js/**/*.js') //select all javascript files under js/ and any subdirectory
.pipe(sourcemaps.init())
.pipe(concat('sencamer.min.js')) //the name of the resulting file
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('src/AppBundle/Resources/public/js/min'))
.pipe(livereload());
});
每当我从控制台使用gulp default
执行gulp文件时,我都会收到此输出:
[22:44:40] Using gulpfile /var/www/html/project.dev/gulpfile.js
[22:44:40] Starting 'css'...
[22:44:40] Finished 'css' after 7.86 ms
[22:44:40] Starting 'js'...
[22:44:40] Starting 'watch'...
[22:44:40] Finished 'watch' after 22 ms
[22:44:41] Starting 'css'...
[22:44:41] Finished 'css' after 1.16 ms
[22:44:44] Finished 'js' after 3.6 s
[22:44:44] Starting 'default'...
[22:44:44] Finished 'default' after 3.58 μs
[22:44:44] Starting 'js'...
[22:44:50] Finished 'js' after 6.1 s
[22:44:50] Starting 'js'...
[22:45:01] Finished 'js' after 10 s
[22:45:01] Starting 'js'...
[22:45:14] Finished 'js' after 14 s
[22:45:14] Starting 'js'...
[22:45:31] Finished 'js' after 17 s
[22:45:32] Starting 'js'...
[22:45:51] Finished 'js' after 19 s
[22:45:51] Starting 'js'...
[22:46:14] Finished 'js' after 23 s
[22:46:14] Starting 'js'...
[22:46:42] Finished 'js' after 28 s
[22:46:42] Starting 'js'...
但为什么js
任务一直在执行?我在这里做错了什么?
更新
我在这一行做了一些改动:
gulp.watch('src/AppBundle/Resources/public/js/*.js', ['js'])
但现在我收到了这个错误:
events.js:72
throw er; // Unhandled 'error' event
^
Error
at new JS_Parse_Error (/var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:189:18)
at js_error (/var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:197:11)
at parse_error (/var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:299:9)
at /var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:511:36
at Object.next_token [as input] (/var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:536:36)
at next (/var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:643:25)
at subscripts (/var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:1307:13)
at subscripts (/var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:1288:20)
at expr_atom (/var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:1165:20)
at maybe_unary (/var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:1328:19)
at expr_ops (/var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:1363:24)
at maybe_conditional (/var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:1368:20)
at maybe_assign (/var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:1392:20)
at expression (/var/www/html/project.dev/node_modules/uglify-js/lib/parse.js:1411:20)
为什么呢?仍然watch
查看js/min
目录?
答案 0 :(得分:2)
您正在观看 src / AppBundle / Resources / public /...目录以及写入其中的任务内部。所以在改变后你再次触发任务。
将文件输出到未监视文件的目录。