简体   繁体   English

如何使用Babel和预设启动PM2 Node JS

[英]How to Start PM2 Node JS with Babel and presets

I'm having the following code in my package.json to start the script while developing: 我在package.json中包含以下代码以在开发时启动脚本:

....
    "scripts": {
        "start": "nodemon src/index.js --exec babel-node --presets es2015,stage-2"
      },
....

Now I want to deploy it to production. 现在,我想将其部署到生产中。 When I run npm start everything works fine. 当我运行npm start一切正常。 However, it will shut down when I close the terminal. 但是,当我关闭终端时,它将关闭。 So how can I use it with PM2 ? 那么我如何在PM2中使用它呢?

This is what I've tried: 这是我尝试过的:

pm2 start src/index.js -x babel-node -p es2015,stage-2

You can actually use npm start if you like: 如果愿意,您可以实际使用npm start

$ pm2 start npm -- start

That said, for production deployment I would strongly recommend a) using a config file for your pm2 startup stuff (so you can bundle environment variables and such) and b) precompiling your assets as a build step rather than on startup. 也就是说,对于生产部署,我强烈建议a)为您的pm2启动素材使用配置文件(以便您可以捆绑环境变量等),以及b)作为构建步骤而不是在启动时预编译资产。

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

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