我曾经有过“gulp watch”工作正常。在我执行 npm install run-sequence 之后,我的“gulp watch”不再运行。运行 gulp 可以处罚款。看起来任何文件系统更改都不会触发“gulp watch”运行。
以下是我的gulpfile和NPM包。
我曾经有过“gulp watch”工作正常。在我执行 npm install run-sequence 之后,我的“gulp watch”不再运行。运行 gulp 可以处罚款。看起来任何文件系统更改都不会触发“gulp watch”运行。
以下是我的gulpfile和NPM包。
const del = require('del');
const gulp = require('gulp');
const ext_replace = require('gulp-ext-replace');
const nunjucks = require('gulp-nunjucks');
const rename = require("gulp-rename");
var sequence = require('run-sequence');
const sass = require('gulp-sass');
const watch = require('gulp-watch');
var spawn = require('child_process').spawn;
// delete dist folder
gulp.task('clean', function(){
return del.sync(['dist/**']);
});
// compile boostrap
gulp.task('compile-boostrap', function(done) {
spawn('npm', ['run', 'dist'], { cwd: 'src/bootstrap/', stdio: 'inherit', shell: true })
.on('close', done);
});
// copy Bootstrap
gulp.task('copy-bootstrap', () =>
gulp.src('src/bootstrap/dist/**/*')
.pipe(gulp.dest('dist/bootstrap/dist'))
);
// copy boostrap vendor
gulp.task('copy-bootstrap-vendor', () =>
gulp.src('src/bootstrap/assets/js/vendor/**/*')
.pipe(gulp.dest('dist/bootstrap/dist/js/vendor'))
);
// css task
gulp.task('copy-css', () =>
gulp.src('src/css/*.css')
.pipe(gulp.dest('dist/css'))
);
// js task
gulp.task('copy-js', () =>
gulp.src('src/js/*.js')
.pipe(gulp.dest('dist/js'))
);
// image task
gulp.task('copy-images', () =>
gulp.src('src/images/*.*')
.pipe(gulp.dest('dist/images'))
);
gulp.task('sass', () =>
gulp.src('src/css/*.scss')
.pipe(sass({sourcemap: true}))
.on('error', sass.logError)
.pipe(gulp.dest('dist/css'))
);
// bower components
gulp.task('copy-bower', () =>
gulp.src('src/bower_components/**/*')
.pipe(gulp.dest('dist/bower_components'))
);
//template data
// today
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1;
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
// item list
item_list = []
for (i = 0; i < 9; i++) {
item = {'name':'My Item',
'location': 'NY, NY',
'rating': 4,
'img_src': 'images/no_image.png'};
item_list.push(item);
}
// suggest list
suggest_list = []
for (i = 0; i < 10; i++) {
item = {'name':'Suggested ittem',
'location': 'NY, NY',
'rating': 4,
'img_src': 'images/no_image.png'};
suggest_list.push(item);
}
// comment list
comment_list = []
for (i = 0; i < 10; i++) {
comment = {'username':'Comment Username',
'comment': 'This is my comment',
'date': today,
'img_src': 'images/no_image.png'};
comment_list.push(comment);
}
// review list
review_list = []
for (i = 0; i < 10; i++) {
review = {'username':'Review Username',
'review': 'This is my review',
'date': today,
'img_src': 'images/no_image.png'};
review_list.push(review);
}
// user
user = {'username': "My Name",
'email': 'my@email.com',
'img_src': 'images/no_image.png'}
// template task
gulp.task('njk', () =>
gulp.src('src/*.njk')
.pipe(nunjucks.compile({'comment_list': comment_list,
'item_list':item_list,
'suggest_list': suggest_list,
'review_list': review_list,
'user': user}))
.pipe(ext_replace('.html'))
.pipe(gulp.dest('dist'))
);
// "gulp watch" from command line
gulp.task('watch', function() {
gulp.watch('src/**/*', function (event) {
sequence('clean',
'copy-bootstrap',
'copy-bootstrap-vendor',
'copy-css',
'copy-js',
'copy-images',
'sass',
'njk',
'copy-bower');
});
});
// "gulp" from command line
gulp.task('default', function (done) {
sequence('clean',
'compile-boostrap',
'copy-bootstrap',
'copy-bootstrap-vendor',
'copy-css',
'copy-js',
'copy-images',
'sass',
'njk',
'copy-bower',
done);
});
package.json
{
"name": "templates",
"version": "1.0.0",
"description": "",
"main": "gulpfile.js",
"dependencies": {
"del": "^3.0.0",
"gulp": "^3.9.1",
"gulp-exec": "^3.0.1",
"gulp-ext-replace": "^0.3.0",
"gulp-nunjucks": "^3.0.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^3.1.0",
"gulp-watch": "^5.0.0",
"install": "^0.10.1",
"npm": "^5.5.1",
"nunjucks": "^3.0.1"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-sass": "^3.1.0",
"gulp-watch": "^5.0.0",
"run-sequence": "^2.2.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}