aktos-io / scada.js

Industrial distributed SCADA and MRP library for web, desktop and mobile
https://aktos.io
93 stars 26 forks source link

Compile backend Nodejs scripts via Vercel #195

Open ceremcem opened 2 years ago

ceremcem commented 2 years ago

Description:

Compile backend scripts via Vercel in order to improve Ram and CPU usage

https://github.com/vercel/ncc

sourcevault commented 2 years ago

ncc puts all the files in one folder.

[1] For livescript, if you are compiling into dist folder, I suggest you create a seperate bundle folder.

[2] since I use a package.yaml instead of a package.json I use yq to change the entry file for nodejs.

[3] and then after ncc ...., I go back to normal.

It's all there in my makefile as below :

ncc:
  yq w -i src/package.yaml bin.remotemon 'bundle/index.js'  # [2]
  lsc --no-header -cbo dist src
  lsc -cb test
  yaml2json -p src/package.yaml > package.json
  ncc --minify build ./dist/cmdline.js -o ./bundle # [1]
  yq w -i src/package.yaml bin.remotemon 'dist/cmdline.js' # [3]

I compared the timing with rust's exa program, it's x10 slower, but that is better than x60.

rust `exa`   | 0.02s | 1
nodejs + ncc | 0.2s  | 10x
nodejs       | 1.2s  | 60x