How to start Gulp watch task when I type npm start(当我输入 npm start 时如何启动 Gulp watch 任务)
问题描述
我有一个 gulp.js 文件,其中包括:
I have a gulp.js file that includes:
gulp.task('default', ['watch']);
哪个启动了监视任务
gulp.task('watch', function(){
gulp.watch(productionScripts, ['autoConcat']);
});
然后在 productionScripts 中对文件的任何保存更改,监视任务将连接文件.
Then on any saved changes to files in productionScripts, the watch task will concat the files.
我想做的是在我的 package.json 中,我想在我输入 npm start 时启动这个手表(这已经启动了我的节点服务器).
What I would like to do, is in my package.json, I would like to spool up this watch when I type npm start (this already starts my node server).
package.json
package.json
"start": "node server.js",
更新--------
Ben(b3nj4m.com),我试过你所说的.手表和服务器启动.但是,一切都运行了两次(可能是由于编辑器,不相关),但是当我使用 gulp 启动它时,我确实丢失了我的服务器日志.
Ben(b3nj4m.com), I tried what you stated. The watch and server start up. However, everything runs twice (probably due to the editor, not related), but I do lose my server log when I start it up with gulp.
[15:31:18] Starting 'autoConcat'...
[15:31:18] Finished 'autoConcat' after 147 ms
[15:31:19] Starting 'autoConcat'...
[15:31:19] Finished 'autoConcat' after 138 ms
[15:31:20] Starting 'autoConcat'...
[15:31:20] Finished 'autoConcat' after 127 ms
[15:31:23] Starting 'autoConcat'...
这就像在服务器因更改而重新启动和级联文件更改之间存在一个循环.
It's like there is a loop between the server restarting on a change, and the concatenated file changing.
推荐答案
你可以从你的 gulpfile 运行你的服务器:
You could run your server from your gulpfile:
var child = require('child_process');
var fs = require('fs');
gulp.task('default', ['server', 'watch']);
gulp.task('server', function() {
var server = child.spawn('node', ['server.js']);
var log = fs.createWriteStream('server.log', {flags: 'a'});
server.stdout.pipe(log);
server.stderr.pipe(log);
});
gulp.task('watch', function(){
gulp.watch(productionScripts, ['autoConcat']);
});
然后将您的 npm start
定义更改为:
Then change your npm start
definition to look like:
"scripts": {
"start": "gulp"
}
这篇关于当我输入 npm start 时如何启动 Gulp watch 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当我输入 npm start 时如何启动 Gulp watch 任务


基础教程推荐
- 直接将值设置为滑块 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01