How to configure pm2 with webpack for typescripts compile and reload?
Asked Answered
E

2

8

Is there any boiler plate code to use pm2 with webpack watch option for ts files auto hot reload?

pm2 start index.js is helpful to run directly, but how to add multiple tasks before doing it like watch files and auto reload using webpack and pm2 from dist folders?

Elbertina answered 31/3, 2018 at 6:25 Comment(2)
why do you need pm2 in your case? Webpack already has some watch options. Is it just for when it crashes?Assignee
pm2 has more benefits compared to webpack. Hence combination of both is worthElbertina
E
7

After much research considering performance, I might add live reload, which is a to-do task – but not a priority as of now.

"scripts": {
    "build": "webpack --config webpack.config.js --watch",
    "pm2": "pm2 start ./dist/server.js --watch=true",
    "postinstall": "npm run build",
    "test": "jest --forceExit",
    "test-ci": "npm test && cat ./coverage/lcov.info | coveralls",
    "start": "supervisor ./dist/server.js",
    "server:dev": "concurrently \"npm run build \" \"npm run start\""
}
Elbertina answered 7/4, 2018 at 11:22 Comment(0)
C
0

Create a process.json for pm2 config In the script key you can give a webpack compiler to run. I am not sure if it will run for it watch reload.

Cephalad answered 2/4, 2018 at 10:12 Comment(5)
I am not clear with this, can you please explain a bit more. Do we really need webpack as well? Is there any watch mode which compiles and reload typescript using pm2?Elbertina
express-ts I am able to run this project using pm2 start src/server.ts --watch Note that in server.js, I am importing ts-node for transpiling.Cephalad
Thanks for your response @DrEarnest, i am looking for webpack integration along with pm2. So that, it can compile typescripts, uglify or minify and compile sass files as well is my requirementElbertina
In the server.js you can import your config and run it. It will recompile on each watch. require('webpack'); var webpackConfig = require('webpack'.config'); we pack(webpackConfig);Cephalad
A simple working example with hot reload of pm2 plz, ill accept your answer and reward it straight away. It will be great if you can push to the same repository which u have createdElbertina

© 2022 - 2024 — McMap. All rights reserved.