admin管理员组文章数量:1291050
Here's my gulpfile.
var gulp = require('gulp');
var less = require('gulp-less');
var clean = require('gulp-clean');
var mincss = require('gulp-minify-css');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var inject = require('gulp-inject');
var templateCache = require('gulp-angular-templatecache');
var angularFilesort = require('gulp-angular-filesort');
var env = 'development';
gulp.task('default', ['clean'], function() {
gulp.start('static', 'html');
});
gulp.task('production', ['set-production', 'default']);
gulp.task('development', ['default'], function() {
gulp.watch('./src/less/**/*.less', ['styles']);
gulp.watch('./src/js/**/*.js', ['scripts']);
gulp.watch('./*.html', ['html']);
});
gulp.task('static', function() {
return gulp.src(['./src/static/*.*'])
.pipe(gulp.dest('./dist/static'));
});
gulp.task('clean', function() {
return gulp.src('./dist', {
read: false
})
.pipe(clean());
});
gulp.task('html', ['styles', 'vendor-js', 'templateCache', 'scripts'], function() {
return gulp.src('./*.html')
.pipe(inject(gulp.src(['./dist/js/**/*.js'])
.pipe(angularFilesort()), {
'ignorePath': 'dist/js',
'addRootSlash': false,
'addPrefix': 'scripts'
}))
.pipe(inject(gulp.src(['./dist/vendors/**/*.js', '!./dist/vendors/less/less.js'], {
read: false
}), {
'name': 'vendors',
'ignorePath': 'dist/vendors',
'addRootSlash': false,
'addPrefix': 'vendors'
}))
.pipe(inject(gulp.src(['./dist/css/*.css'], {
read: false
}), {
'ignorePath': 'dist/css',
'addRootSlash': false,
'addPrefix': 'styles'
}))
.pipe(gulp.dest('dist'));
});
gulp.task('styles', function() {
return gulp.src('./src/less/*.less')
.pipe(less())
.pipe(gulpif(env === 'production', mincss()))
.pipe(gulpif(env === 'production', concat('styles.css')))
.pipe(gulp.dest('dist/css'));
});
gulp.task('scripts', function() {
return gulp.src('./src/js/**/*.js')
.pipe(gulpif(env === 'production', uglify()))
.pipe(gulpif(env === 'production', concat('scripts.js')))
.pipe(gulp.dest('dist/js'));
});
gulp.task('vendor-js', function() {
return gulp.src(['./vendors/jQuery/jquery-1.11.1.js', 'vendors/angular/angular.js'])
.pipe(concat('vendors.js'))
.pipe(gulp.dest('dist/vendors'));
});
gulp.task('templateCache', function() {
return gulp.src('./src/js/**/*.tpl.html')
.pipe(templateCache('templatesCache.js', {
module: 'templatesCache',
standalone: true,
root: './templates/'
}))
.pipe(gulp.dest('./dist/js'));
});
gulp.task('set-production', function() {
env = 'production';
});
When I run "gulp development", it goes into an infinite loop like this.
I am sure there is an issue with the way I am trying to watch stuff. Can someone help me out with this?
Thanks!
Here's my gulpfile.
var gulp = require('gulp');
var less = require('gulp-less');
var clean = require('gulp-clean');
var mincss = require('gulp-minify-css');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var inject = require('gulp-inject');
var templateCache = require('gulp-angular-templatecache');
var angularFilesort = require('gulp-angular-filesort');
var env = 'development';
gulp.task('default', ['clean'], function() {
gulp.start('static', 'html');
});
gulp.task('production', ['set-production', 'default']);
gulp.task('development', ['default'], function() {
gulp.watch('./src/less/**/*.less', ['styles']);
gulp.watch('./src/js/**/*.js', ['scripts']);
gulp.watch('./*.html', ['html']);
});
gulp.task('static', function() {
return gulp.src(['./src/static/*.*'])
.pipe(gulp.dest('./dist/static'));
});
gulp.task('clean', function() {
return gulp.src('./dist', {
read: false
})
.pipe(clean());
});
gulp.task('html', ['styles', 'vendor-js', 'templateCache', 'scripts'], function() {
return gulp.src('./*.html')
.pipe(inject(gulp.src(['./dist/js/**/*.js'])
.pipe(angularFilesort()), {
'ignorePath': 'dist/js',
'addRootSlash': false,
'addPrefix': 'scripts'
}))
.pipe(inject(gulp.src(['./dist/vendors/**/*.js', '!./dist/vendors/less/less.js'], {
read: false
}), {
'name': 'vendors',
'ignorePath': 'dist/vendors',
'addRootSlash': false,
'addPrefix': 'vendors'
}))
.pipe(inject(gulp.src(['./dist/css/*.css'], {
read: false
}), {
'ignorePath': 'dist/css',
'addRootSlash': false,
'addPrefix': 'styles'
}))
.pipe(gulp.dest('dist'));
});
gulp.task('styles', function() {
return gulp.src('./src/less/*.less')
.pipe(less())
.pipe(gulpif(env === 'production', mincss()))
.pipe(gulpif(env === 'production', concat('styles.css')))
.pipe(gulp.dest('dist/css'));
});
gulp.task('scripts', function() {
return gulp.src('./src/js/**/*.js')
.pipe(gulpif(env === 'production', uglify()))
.pipe(gulpif(env === 'production', concat('scripts.js')))
.pipe(gulp.dest('dist/js'));
});
gulp.task('vendor-js', function() {
return gulp.src(['./vendors/jQuery/jquery-1.11.1.js', 'vendors/angular/angular.js'])
.pipe(concat('vendors.js'))
.pipe(gulp.dest('dist/vendors'));
});
gulp.task('templateCache', function() {
return gulp.src('./src/js/**/*.tpl.html')
.pipe(templateCache('templatesCache.js', {
module: 'templatesCache',
standalone: true,
root: './templates/'
}))
.pipe(gulp.dest('./dist/js'));
});
gulp.task('set-production', function() {
env = 'production';
});
When I run "gulp development", it goes into an infinite loop like this.
I am sure there is an issue with the way I am trying to watch stuff. Can someone help me out with this?
Thanks!
Share Improve this question edited Dec 15, 2014 at 10:32 Preview 35.8k10 gold badges95 silver badges113 bronze badges asked Dec 13, 2014 at 18:49 stripathistripathi 78611 silver badges23 bronze badges 1- Your screen doesn't show any loop – Preview Commented Dec 13, 2014 at 21:07
1 Answer
Reset to default 10I think your problem es from your html
watcher.
The fact you're watching for changes on all your .html
files to launch the html
task, that is injecting references to your scripts and your styles files into the index.html
will cause this infinite loop.
Just when the files are finished to be injected and written to the disk, the final dest
of your html
task, this trigger your watcher that restart everything again and again.
So remove the watcher or exclude the index.html
from the watcher to prevent the restarts
gulp.watch(['./*.html', '!index.html'], ['html']);
本文标签: javascriptgulpwatch going into endless loopStack Overflow
版权声明:本文标题:javascript - gulp.watch going into endless loop - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741517751a2382995.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论