简体   繁体   English

永远运行Gulp脚本?

[英]Run Gulp script with forever?

Is it possible to run Gulp script with forever ? 是否有可能永远运行Gulp脚本?

I have Gulp script that would like to run as a daemon, so I could start / stop / list it. 我有Gulp脚本想要作为守护进程运行,所以我可以启动/停止/列出它。

Okay, so I solved it by linking the gulp binary from /usr/bin to my local folder and then simply running the command locally. 好的,所以我通过将/ usr / bin中的gulp二进制文件链接到我的本地文件夹然后在本地运行命令来解决它。 Like so: 像这样:

ln -s /usr/bin/gulp ./gulp
forever start gulp serve

The commands may vary for you but I hope you get the gist of it. 命令可能会有所不同,但我希望你能得到它的要点。

如果你在节点项目中安装gulp ,你可以这样做:

forever start node_modules/gulp/bin/gulp.js [YOUR GULP TASK]

To give you a programatic answer: 给你一个程序化的答案:

You use the underlying forever-monitor which contains the core functionality which the forever CLI package uses. 您使用底层的forever-monitor ,它包含forever CLI包使用的核心功能。

var forever = require('forever-monitor');

gulp.task('server', function () {
    new forever.Monitor('path/to/server-script.js').start();
});

You can run multiples of such tasks, you don't need to use special daemon options since gulp tasks use orchestrator under the hood which runs tasks concurrently. 您可以运行多个此类任务,您不需要使用特殊的守护程序选项,因为gulp任务使用orchestrator同时运行任务。

If using CMD+C in the console is not suitable to stop your tasks then you can put it into a variable: 如果在控制台中使用CMD + C不适合停止任务,那么可以将其放入变量中:

var child = new forever.Monitor('path/to/server-script.js');
child.on('event', cb) / child.start() / child.stop()

Install pm2 安装pm2

$ npm install pm2 -g

Now start gulp 现在开始gulp

pm2 start gulp serve

You can view running services using pm2 l and Note: sometimes you can see your services running on next to port you specified example: http://localhost:3001 instead of http://localhost:3000 您可以使用pm2 l查看正在运行的服务并注意:有时您可以看到在您指定的端口旁边运行的服务示例: http:// localhost:3001而不是http:// localhost:3000

Try this: 尝试这个:

forever start -c "gulp" serve

The -c option allows you to use any command. -c选项允许您使用任何命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM