有一个 Node.js 脚本prod.js可以在特定端口上启动开发服务器。
const { execSync } = require('child_process')
process.env.NODE_ENV = 'production'
const WEBPACK_PATH = 'node_modules/.bin/webpack'
const WEBPACK_CONFIG_PATH = 'internals/webpack/configs/prod'
execSync('yarn install --production=false')
execSync('rm -rf ./build')
execSync(`"${WEBPACK_PATH}" --config "${WEBPACK_CONFIG_PATH}"/webpack.prod.client.babel.js --display-error-details`)
execSync(`"${WEBPACK_PATH}" --config "${WEBPACK_CONFIG_PATH}"/webpack.prod.server.babel.js --display-error-details`)
execSync('node ./scripts/server/start-server.babel.js')
有可能妖魔化它吗?让他做以下事情
- 在机器的物理重启时启动(非常必要)
- 响应文件更改
- 杀死指定端口上的进程
我找到了几个模块:pm2和nodemon,但是,我没有看到它们能够在系统启动时自动启动。
另外,尝试过nodemon,但是,命令是
nodemon ./prod.js
陷入永久重启,因此,进程甚至无法启动
[nodemon] restarting due to changes...
[nodemon] starting `node scripts/prod.js`
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] starting `node scripts/prod.js`
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
谁遇到过类似的问题,请告诉我?
您可以使用node-windows,有机会制作本机 Windows 服务。