Build minified for production (#155)
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 15 Feb 2021 15:55:38 +0000 (16:55 +0100)
committerGitHub <noreply@github.com>
Mon, 15 Feb 2021 15:55:38 +0000 (16:55 +0100)
* Build minified for production

And use dev build in CI

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* Rename scripts:

nothing -> default dev build
:prod -> production build

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* Trigger build analysis output on demand via an env variable

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* Always register source map support.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* Revert to one build output for coverage on sonar cloud.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* Revert "Revert to one build output for coverage on sonar cloud."

This reverts commit f3d990ba9878e4e6f097844cacba9e8e4b4c9121.

* Try with sourcemap: false

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* Build with sourcemap: true

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* Go back to previous sourcemap setting.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* Change sonar sources

Co-authored-by: Alessandro Pio Ardizio <alessandroardizio94@gmail.com>
.eslintignore
.github/workflows/npmpublish.yml
.gitignore
.prettierignore
.vscode/launch.json
.vscode/tasks.json
package.json
rollup.config.mjs
sonar-project.properties

index b7d3d591f81c519fd8a47af9167de549f5e5d3a8..c3af857904ebfd987602da36b219a186a84e4e7a 100644 (file)
@@ -1,2 +1 @@
 lib/
-lib.min/
index 31b02ef4c6e2016e8e88b6daaf4d3e2292b84a42..0692856dc364fadb3529a0941f1efb318b1994c2 100644 (file)
@@ -18,7 +18,7 @@ jobs:
           node-version: 12
       - run: npm ci
       - run: npm run lint
-      - run: npm run test
+      - run: npm run test:prod
       - run: npm run coverage
 
   publish-npm:
index c918d5dd19c968d7e82cf7dd08f92bc8de7e127e..2e2848ad7a6cf6c1378b3b30b6923f93185a563b 100644 (file)
@@ -50,4 +50,3 @@ jspm_packages
 .history/
 .scannerwork
 lib
-lib.min
index f5df346941e775c00c7b275067df72c9506dd7c8..e40d57b1e25c381fbadae36741e29467be34e9a1 100644 (file)
@@ -1,4 +1,3 @@
 .nyc_output/
 coverage/
 lib/
-lib.min/
index c2c4c33f19bc39cdc7a5dc966f14967c8e0dea0a..f62ecf671b713103fd2c20fe565b3487f2a1a804 100644 (file)
@@ -9,9 +9,9 @@
       "request": "launch",
       "name": "Launch Test Debug",
       "cwd": "${workspaceFolder}",
-      "preLaunchTask": "Development build",
+      // "preLaunchTask": "Development build",
       "runtimeExecutable": "npm",
-      "runtimeArgs": ["run-script", "test:debug:vscode"],
+      "runtimeArgs": ["run-script", "test:debug"],
       "skipFiles": ["<node_internals>/**"],
       "stopOnEntry": true
     },
@@ -20,9 +20,9 @@
       "request": "launch",
       "name": "Launch Benchmark Debug",
       "cwd": "${workspaceFolder}",
-      "preLaunchTask": "Development build",
+      // "preLaunchTask": "Development build",
       "runtimeExecutable": "npm",
-      "runtimeArgs": ["run-script", "benchmark:debug:vscode"],
+      "runtimeArgs": ["run-script", "benchmark:debug"],
       "skipFiles": ["<node_internals>/**"],
       "stopOnEntry": true
     }
index ed1577700c35c42b9a2a0f9e26e262a7150c4b14..a6d60cd7e5c139f87ade991ffc21fd12663cf98d 100644 (file)
@@ -1,10 +1,15 @@
 {
   "version": "2.0.0",
   "tasks": [
+    {
+      "label": "Build",
+      "type": "npm",
+      "script": "build:prod"
+    },
     {
       "label": "Development build",
       "type": "npm",
-      "script": "build:dev"
+      "script": "build"
     }
   ]
 }
index 37d39f32e144f71224a0a58133c9c5acc649c593..4e5b8572bc106ee187c7d24f215dfe21ca4ae191 100644 (file)
@@ -4,14 +4,14 @@
   "description": "Library on top of node js worker threads that implement various worker pools type",
   "main": "lib/index.js",
   "scripts": {
-    "build": "rollup --config",
-    "build:dev": "rollup --config --environment BUILD:development",
-    "benchmark": "npm run build && node benchmarks/bench.js",
-    "benchmark:debug": "npm run build:dev && node -r source-map-support/register --inspect-brk benchmarks/bench.js",
-    "benchmark:debug:vscode": "node -r source-map-support/register benchmarks/bench.js",
-    "test": "npm run build && nyc mocha --exit --timeout 20000 tests/**/*.test.js",
-    "test:debug": "npm run build:dev && mocha -r source-map-support/register --inspect-brk --exit tests/**/*.test.js",
-    "test:debug:vscode": "mocha -r source-map-support/register --exit tests/**/*.test.js",
+    "build": "rollup --config --environment BUILD:development",
+    "build:prod": "rollup --config",
+    "benchmark": "npm run build && node -r source-map-support/register benchmarks/bench.js",
+    "benchmark:debug": "npm run build && node -r source-map-support/register --inspect benchmarks/bench.js",
+    "benchmark:prod": "npm run build:prod && node -r source-map-support/register benchmarks/bench.js",
+    "test": "npm run build && nyc mocha -r source-map-support/register --exit --timeout 20000 tests/**/*.test.js",
+    "test:debug": "npm run build && mocha -r source-map-support/register --inspect --exit --timeout 20000 tests/**/*.test.js",
+    "test:prod": "npm run build:prod && nyc mocha -r source-map-support/register --exit --timeout 20000 tests/**/*.test.js",
     "sonar": "sonar-scanner",
     "coverage": "nyc report --reporter=lcov --check-coverage --lines 80",
     "coverage:html": "nyc report --reporter=html --check-coverage --lines 80",
index 8afbc006de8827bccd162a14d2d3a1d4e33de695..bac8f614a5524bd3983969c29ef1d4b36f6fb202 100644 (file)
@@ -4,24 +4,18 @@ import { terser } from 'rollup-plugin-terser'
 import del from 'rollup-plugin-delete'
 
 const isDevelopmentBuild = process.env.BUILD === 'development'
+const isAnalyze = process.env.ANALYZE
 
 export default {
   input: 'src/index.ts',
-  output: [
-    {
-      dir: 'lib',
-      format: 'cjs',
-      sourcemap: !!isDevelopmentBuild,
-      preserveModules: true,
-      preserveModulesRoot: 'src'
-    },
-    isDevelopmentBuild && {
-      file: 'lib.min/index.js',
-      format: 'cjs',
-      sourcemap: !!isDevelopmentBuild,
-      plugins: [terser({ numWorkers: 2 })]
-    }
-  ],
+  output: {
+    ...(isDevelopmentBuild ? { dir: 'lib' } : { file: 'lib/index.js' }),
+    format: 'cjs',
+    sourcemap: !!isDevelopmentBuild,
+    ...(isDevelopmentBuild && { preserveModules: true }),
+    ...(isDevelopmentBuild && { preserveModulesRoot: 'src' }),
+    ...(!isDevelopmentBuild && { plugins: [terser({ numWorkers: 2 })] })
+  },
   external: ['async_hooks', 'cluster', 'events', 'worker_threads'],
   plugins: [
     typescript({
@@ -30,8 +24,8 @@ export default {
         : 'tsconfig.json'
     }),
     del({
-      targets: ['lib/*', 'lib.min/*']
+      targets: ['lib/*']
     }),
-    isDevelopmentBuild && analyze()
+    isAnalyze && analyze()
   ]
 }
index 846b8a5ac99f32bcdb7eda8d8cf9679824e54a08..4bd411a059030ac90e5dba334db47b4451ff5509 100644 (file)
@@ -4,7 +4,7 @@ sonar.javascript.lcov.reportPaths=coverage/lcov.info
 sonar.projectName=poolifier
 sonar.projectVersion=2.0.0
 sonar.host.url=https://sonarcloud.io
-sonar.sources=lib
+sonar.sources=src
 sonar.tests=tests
 # sonar.login=TOKEN #To use for local troubleshooting
 sonar.verbose=false