Minify production build
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 14 Feb 2021 19:55:26 +0000 (20:55 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 14 Feb 2021 19:55:26 +0000 (20:55 +0100)
And fix GitHub CI.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
.github/workflows/build.yml
.vscode/launch.json
.vscode/tasks.json
mta.yaml
package-lock.json
package.json
rollup.config.js

index d42c3e0ba7c3056528ddd1f9438a9558a2bd2075..583ffff14da3bae816e60a58b3e9f66b1f6777e1 100644 (file)
@@ -20,5 +20,5 @@ jobs:
         node-version: ${{ matrix.node-version }}
     - name: npm install
       run: npm ci
-    - name: npm run build:prod
-      run: npm run build:prod
+    - name: npm run build
+      run: npm run build
index 8c879c6e4f77d876ccfbf85511fcdd93db9dbf85..5c8aa82b4f96dcd045bf6d9fc96aa11a2422d5d1 100644 (file)
@@ -7,7 +7,7 @@
     {
       "type": "pwa-node",
       "request": "launch",
-      "name": "Debug Program via npm",
+      "name": "Debug Simulator via npm",
       "cwd": "${workspaceFolder}",
       "preLaunchTask": "Build",
       "runtimeExecutable": "npm",
         "<node_internals>/**"
       ],
       "stopOnEntry": true
+    },
+    {
+      "type": "pwa-node",
+      "request": "launch",
+      "name": "Debug Simulator Development Build via npm",
+      "cwd": "${workspaceFolder}",
+      "runtimeExecutable": "npm",
+      "runtimeArgs": [
+        "run-script",
+        "start:dev:debug"
+      ],
+      "skipFiles": [
+        "<node_internals>/**"
+      ],
+      "stopOnEntry": true
     }
   ]
 }
index 343bcdc254bf9bcc46d0f807ae8c3e4bb2898298..62d341649cb7f55d43d777af7f3934017b079be3 100644 (file)
@@ -5,6 +5,11 @@
       "label": "Build",
       "type": "npm",
       "script": "build"
+    },
+    {
+      "label": "Development Build",
+      "type": "npm",
+      "script": "build:dev"
     }
   ]
 }
index ecb763097a339b0cc06dfba716cbb44f7ba25cfe..6fa93508e6ab3a15e2ad9a836d2181f6c29cc070 100644 (file)
--- a/mta.yaml
+++ b/mta.yaml
@@ -7,7 +7,7 @@ build-parameters:
     - builder: custom
       commands:
         - npm install
-        - npm run build:prod
+        - npm run build
 
 resources:
   - name: dynatrace-service
index c20844244d05d49ce34a4513c79af148db027075..c2c176e36a9bc867dc70898fc41bd537b60d8cf1 100644 (file)
       "dev": true
     },
     "@types/node": {
-      "version": "14.14.27",
-      "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.27.tgz",
-      "integrity": "sha512-Ecfmo4YDQPwuqTCl1yBxLV5ihKfRlkBmzUEDcfIRvDxOTGQEeikr317Ln7Gcv0tjA8dVgKI3rniqW2G1OyKDng==",
+      "version": "14.14.28",
+      "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.28.tgz",
+      "integrity": "sha512-lg55ArB+ZiHHbBBttLpzD07akz0QPrZgUODNakeC09i62dnrywr9mFErHuaPlB6I7z+sEbK+IYmplahvplCj2g==",
       "dev": true
     },
     "@types/offscreencanvas": {
       "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=",
       "dev": true
     },
+    "jest-worker": {
+      "version": "26.6.2",
+      "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-26.6.2.tgz",
+      "integrity": "sha512-KWYVV1c4i+jbMpaBC+U++4Va0cp8OisU185o73T1vo99hqi7w8tSJfUXYswwqqrjzwxa6KpRK54WhPvwf5w6PQ==",
+      "dev": true,
+      "requires": {
+        "@types/node": "*",
+        "merge-stream": "^2.0.0",
+        "supports-color": "^7.0.0"
+      },
+      "dependencies": {
+        "has-flag": {
+          "version": "4.0.0",
+          "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
+          "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
+          "dev": true
+        },
+        "supports-color": {
+          "version": "7.2.0",
+          "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
+          "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
+          "dev": true,
+          "requires": {
+            "has-flag": "^4.0.0"
+          }
+        }
+      }
+    },
     "js-tokens": {
       "version": "4.0.0",
       "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
         "source-map": "^0.5.6"
       }
     },
+    "merge-stream": {
+      "version": "2.0.0",
+      "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
+      "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==",
+      "dev": true
+    },
     "merge2": {
       "version": "1.4.1",
       "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz",
         "del": "^5.1.0"
       }
     },
+    "rollup-plugin-terser": {
+      "version": "7.0.2",
+      "resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz",
+      "integrity": "sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==",
+      "dev": true,
+      "requires": {
+        "@babel/code-frame": "^7.10.4",
+        "jest-worker": "^26.2.1",
+        "serialize-javascript": "^4.0.0",
+        "terser": "^5.0.0"
+      },
+      "dependencies": {
+        "source-map": {
+          "version": "0.7.3",
+          "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz",
+          "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==",
+          "dev": true
+        },
+        "terser": {
+          "version": "5.6.0",
+          "resolved": "https://registry.npmjs.org/terser/-/terser-5.6.0.tgz",
+          "integrity": "sha512-vyqLMoqadC1uR0vywqOZzriDYzgEkNJFK4q9GeyOBHIbiECHiWLKcWfbQWAUaPfxkjDhapSlZB9f7fkMrvkVjA==",
+          "dev": true,
+          "requires": {
+            "commander": "^2.20.0",
+            "source-map": "~0.7.2",
+            "source-map-support": "~0.5.19"
+          }
+        }
+      }
+    },
     "rollup-plugin-typescript2": {
       "version": "0.29.0",
       "resolved": "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.29.0.tgz",
         "semver": "^5.0.3"
       }
     },
+    "serialize-javascript": {
+      "version": "4.0.0",
+      "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-4.0.0.tgz",
+      "integrity": "sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw==",
+      "dev": true,
+      "requires": {
+        "randombytes": "^2.1.0"
+      }
+    },
     "set-blocking": {
       "version": "2.0.0",
       "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
index dc329d53fe0ccdd0d5649129ec0f76d23772fd9e..223314a59f177bb5942872c444d98616657df117 100644 (file)
@@ -23,6 +23,8 @@
     "prestart": "npm run build",
     "start": "cross-env NODE_ENV=production node -r source-map-support/register dist/start.js",
     "start:debug": "cross-env NODE_ENV=production node -r source-map-support/register --inspect dist/start.js",
+    "start:dev": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register dist/start.js",
+    "start:dev:debug": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register --inspect dist/start.js",
     "start:prof": "cross-env NODE_ENV=production node -r source-map-support/register --prof dist/start.js",
     "start:doctorprof": "cross-env NODE_ENV=production clinic doctor -- node -r source-map-support/register dist/start.js",
     "start:flameprof": "cross-env NODE_ENV=production clinic flame -- node -r source-map-support/register dist/start.js",
@@ -59,7 +61,7 @@
     "utf-8-validate": "^5.0.4"
   },
   "devDependencies": {
-    "@types/node": "^14.14.27",
+    "@types/node": "^14.14.28",
     "@types/uuid": "^8.3.0",
     "@types/ws": "^7.4.0",
     "@typescript-eslint/eslint-plugin": "^4.15.0",
@@ -73,6 +75,7 @@
     "rollup-plugin-analyzer": "^4.0.0",
     "rollup-plugin-copy": "^3.3.0",
     "rollup-plugin-delete": "^2.0.0",
+    "rollup-plugin-terser": "^7.0.2",
     "rollup-plugin-typescript2": "^0.29.0",
     "typescript": "^4.1.5"
   }
index 16624fced18a1d063567805f42f069b6a20ae270..2184bb6e5657cb5ec4f5425dbcb24a89e61184f7 100644 (file)
@@ -1,19 +1,22 @@
 import analyze from 'rollup-plugin-analyzer';
 import copy from 'rollup-plugin-copy';
 import del from 'rollup-plugin-delete';
+import { terser } from 'rollup-plugin-terser';
 import typescript from 'rollup-plugin-typescript2';
 
 const isDevelopmentBuild = process.env.BUILD === 'development';
 
 export default {
   input: ['src/start.ts', 'src/charging-station/StationWorker.ts'],
-  output: {
+  output:
+  {
     dir: 'dist',
     format: 'cjs',
     exports: 'auto',
     sourcemap: true,
     preserveModules: true,
-    preserveModulesRoot: 'src'
+    preserveModulesRoot: 'src',
+    ...!isDevelopmentBuild && { plugins: [terser({ numWorkers: 2 })] }
   },
   external: ['crypto', 'perf_hooks', 'fs', 'path', 'poolifier', 'uuid', 'ws', 'winston-daily-rotate-file', 'winston/lib/winston/transports', 'winston', 'worker_threads'],
   plugins: [