下面是我的 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);
});
*Config.start_page 指向 dist/index.html