Javascript 狼吞虎咽';打开';任务不存在';不能正确执行
下面是我的gulpfile中的代码片段,我遇到的主要问题是,每当从CLI执行“gulp”时,open并不总是打开新的浏览器窗口。例如,如果我删除生成的'dist'文件夹并执行'gulp',则'dist'将与.html文件和资产结构分离,但它将无法在我的浏览器窗口中打开站点 如果我随后取消当前正在运行的gulp任务并再次从CLI执行它(在“dist”文件夹就位的情况下),则gulp将在新的浏览器窗口中加载站点 如何设置open,使其无论发生什么情况都能每次执行?我认为这与“清洁”任务有冲突,但我不太确定 任何帮助都将不胜感激 清理任务:Javascript 狼吞虎咽';打开';任务不存在';不能正确执行,javascript,node.js,gulp,Javascript,Node.js,Gulp,下面是我的gulpfile中的代码片段,我遇到的主要问题是,每当从CLI执行“gulp”时,open并不总是打开新的浏览器窗口。例如,如果我删除生成的'dist'文件夹并执行'gulp',则'dist'将与.html文件和资产结构分离,但它将无法在我的浏览器窗口中打开站点 如果我随后取消当前正在运行的gulp任务并再次从CLI执行它(在“dist”文件夹就位的情况下),则gulp将在新的浏览器窗口中加载站点 如何设置open,使其无论发生什么情况都能每次执行?我认为这与“清洁”任务有冲突,但我不
gulp.task('clean', function() {
gulp.src(['./dist/**/*.*'], { read: true })
.pipe(clean())
});
gulp.task('open', function() {
gulp.src(config.startpage)
.pipe(open(config.startpage, { url: 'http://localhost:'+config.http_port }));
});
gulp.task('default', ['html', 'scripts', 'styles', 'images', 'open', 'clean'], function() {
server.listen(config.livereload_port);
http.createServer(ecstatic({ root: 'dist/' } )).listen(config.http_port);
// gutil.log(gutil.colors.yellow('HTTP Server running on port:'), gutil.colors.red(config.http_port));
gulp.watch(config.src_sass, ['styles'])._watcher.on('all', livereload);
gulp.watch(config.src_js, ['scripts'])._watcher.on('all', livereload);
gulp.watch(config.src_html, ['html'])._watcher.on('all', livereload);
});
打开任务:
gulp.task('clean', function() {
gulp.src(['./dist/**/*.*'], { read: true })
.pipe(clean())
});
gulp.task('open', function() {
gulp.src(config.startpage)
.pipe(open(config.startpage, { url: 'http://localhost:'+config.http_port }));
});
gulp.task('default', ['html', 'scripts', 'styles', 'images', 'open', 'clean'], function() {
server.listen(config.livereload_port);
http.createServer(ecstatic({ root: 'dist/' } )).listen(config.http_port);
// gutil.log(gutil.colors.yellow('HTTP Server running on port:'), gutil.colors.red(config.http_port));
gulp.watch(config.src_sass, ['styles'])._watcher.on('all', livereload);
gulp.watch(config.src_js, ['scripts'])._watcher.on('all', livereload);
gulp.watch(config.src_html, ['html'])._watcher.on('all', livereload);
});
默认任务:
gulp.task('clean', function() {
gulp.src(['./dist/**/*.*'], { read: true })
.pipe(clean())
});
gulp.task('open', function() {
gulp.src(config.startpage)
.pipe(open(config.startpage, { url: 'http://localhost:'+config.http_port }));
});
gulp.task('default', ['html', 'scripts', 'styles', 'images', 'open', 'clean'], function() {
server.listen(config.livereload_port);
http.createServer(ecstatic({ root: 'dist/' } )).listen(config.http_port);
// gutil.log(gutil.colors.yellow('HTTP Server running on port:'), gutil.colors.red(config.http_port));
gulp.watch(config.src_sass, ['styles'])._watcher.on('all', livereload);
gulp.watch(config.src_js, ['scripts'])._watcher.on('all', livereload);
gulp.watch(config.src_html, ['html'])._watcher.on('all', livereload);
});
*Config.start\u页面指向dist/index.html您有两个相关问题:
gulp.task('clean', function() {
return gulp.src(['./dist/**/*.*'], { read: true })
.pipe(clean())
});
默认任务中,这些依赖项将同时运行,除非它们相互依赖
由于我怀疑您是否希望在每次运行其他任务时强制执行clean
任务,因此另一种解决方案是使用。(这是我的图书馆,是为了解决这个问题而写的。)最终,希望他们能找到一种方法来解决这个问题
注意:您仍然需要修复问题1,才能使运行序列
正常工作
使用您的插件,我可以将我的运行顺序更改为:runSequence('clean',['scripts','styles','images','html'],'open',callback);-谢谢,它工作得非常好!