Run Gulp script with forever?

2019-04-04 02:17发布

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.

5条回答
Anthone
2楼-- · 2019-04-04 02:47

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()
查看更多
小情绪 Triste *
3楼-- · 2019-04-04 02:56

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

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

查看更多
\"骚年 ilove
4楼-- · 2019-04-04 03:06

Try this:

forever start -c "gulp" serve

The -c option allows you to use any command.

查看更多
Explosion°爆炸
5楼-- · 2019-04-04 03:07

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.

查看更多
▲ chillily
6楼-- · 2019-04-04 03:12

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

查看更多
登录 后发表回答