下面是我的gulp文件中的代码片段,基本上我遇到的问题是,只要从CLI执行'gulp',open并不总是打开新的浏览器窗口。例如,如果我删除生成的'dist'文件夹并执行'gulp',那么'dist'将支持.html文件和资产结构,但它将无法在我的浏览器窗口中打开该网站...Gulp'Open'任务无法正确执行
如果我然后取消当前正在运行的gulp任务,并再次从CLI执行它(使用'dist'文件夹),那么gulp会将该站点加载到新的浏览器窗口中,因为它应该如此。
我该如何设置打开方式,以便每次都执行?我认为它以某种方式与'干净'任务发生冲突,但我不太确定。
任何帮助,将不胜感激。
清洁任务:
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_page婆整型到dist/index.html的
随着你的插件我能我跑顺序更改为:runSequence( '干净',[ '脚本', '风格', '图像', 'HTML'], '开放',回调) ; - 谢谢,它的效果非常好! – leaksterrr