Run Gulp script with forever?

試著忘記壹切 提交于 2019-12-12 08:19:46

问题


Is it possible to run Gulp script with forever?

I have Gulp script that would like to run as a daemon, so I could start / stop / list it.


回答1:


Okay, so I solved it by linking the gulp binary from /usr/bin to my local folder and then simply running the command locally. 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.




回答2:


if you install gulp in your node project, you can do like this:

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




回答3:


To give you a programatic answer:

You use the underlying forever-monitor which contains the core functionality which the forever CLI package uses.

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.

If using CMD+C in the console is not suitable to stop your tasks then you can put it into a variable:

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



回答4:


Install pm2

$ npm install pm2 -g

Now start 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




回答5:


Try this:

forever start -c "gulp" serve

The -c option allows you to use any command.



来源:https://stackoverflow.com/questions/28543171/run-gulp-script-with-forever

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!