Config for PM2 to automatically restart Electron on save. I'm using angular in examples. You can use any other framework.
- Install pm2 globally
npm i -g pm2
- Install typescript and Node types as dev dependency
npm i -D typescript @types/node
Create tsconfig.electron.json
file. In my case, I'm extending angular's tsconfig to preserve the feature set.
Add entries:
{
...
"compilerOptions": {
"outDir": "./dist/electron",
"target": "ES5",
"module": "CommonJS"
},
"include": [
"src/electron/**/*.d.ts",
"src/electron/**/*.ts"
],
"lib": [
"ES2022"
],
...
}
Set output directory to ./dist/{your_framework_name}
Put in scripts
section new entries:
"scripts": {
...
"start": "pm2 start watcher.config.js",
"watch:electron": "npx tsc --project tsconfig.electron.json --watch",
"watch:framework": "ng build --watch --configuration development",
...
},
Angular used as an example.
Create folder runners
. Put file runner.js
inside. For each script create a file, with a name like example.runner.js
. Put inside the startup script.
const Runner = require('./runner.js')
const runner = new Runner('script_you_want_to_launch')
// For example:
// const runner = new Runner('npm run watch:framework')
process.on('exit', () => runner.stop())
Copy file watcher.config.js
to your project root.
Type in your terminal of love npm start
And wait. It can restart a few times during compilation.
You can read logs by going to ~/.pm2/logs
.
I'm using Notepad++ to read them in watch mode.
Also, you can use it in the terminal with pm2 logs {id_of_process}
or pm2 monit
Or in case you want to look total badass use pm2 monitor
and view your logs with the cloud! (Use pm2-webui for an opensource alternative)