From f45e49994cecd326cead15470c28b349b16c8bd0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 14 Feb 2021 09:14:24 +0100 Subject: [PATCH] Build system: add bundling analysis to dev build (#150) --- .eslintignore | 1 + .gitignore | 1 + .prettierignore | 1 + package-lock.json | 82 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ rollup.config.mjs | 29 +++++++++++------ 6 files changed, 107 insertions(+), 9 deletions(-) diff --git a/.eslintignore b/.eslintignore index c3af8579..b7d3d591 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ lib/ +lib.min/ diff --git a/.gitignore b/.gitignore index 2e2848ad..c918d5dd 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,4 @@ jspm_packages .history/ .scannerwork lib +lib.min diff --git a/.prettierignore b/.prettierignore index e40d57b1..f5df3469 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ .nyc_output/ coverage/ lib/ +lib.min/ diff --git a/package-lock.json b/package-lock.json index e376fccb..efed1e62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2682,6 +2682,34 @@ "integrity": "sha512-Gv3ZIs/nA48/Zvjrl34bf+oD76JHiGDUxNOVgUjh3j890sblXryjY4rss71fPtD/njchl6PSE2hIhvyWa1eT0A==", "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", @@ -2883,6 +2911,12 @@ "mimic-fn": "^3.0.0" } }, + "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", @@ -3992,6 +4026,12 @@ "fsevents": "~2.3.1" } }, + "rollup-plugin-analyzer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-analyzer/-/rollup-plugin-analyzer-4.0.0.tgz", + "integrity": "sha512-LL9GEt3bkXp6Wa19SNR5MWcvHNMvuTFYg+eYBZN2OIFhSWN+pEJUQXEKu5BsOeABob3x9PDaLKW7w5iOJnsESQ==", + "dev": true + }, "rollup-plugin-delete": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/rollup-plugin-delete/-/rollup-plugin-delete-2.0.0.tgz", @@ -4001,6 +4041,29 @@ "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": { + "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" + } + } + } + }, "rollup-plugin-typescript2": { "version": "0.29.0", "resolved": "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.29.0.tgz", @@ -4348,6 +4411,25 @@ } } }, + "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" + }, + "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 + } + } + }, "test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", diff --git a/package.json b/package.json index 529bcf0c..ff1376df 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,9 @@ "prettier-plugin-organize-imports": "^1.1.1", "prettierx": "^0.17.0", "rollup": "^2.39.0", + "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-delete": "^2.0.0", + "rollup-plugin-terser": "^7.0.2", "rollup-plugin-typescript2": "^0.29.0", "sonar-scanner": "^3.1.0", "source-map-support": "^0.5.19", diff --git a/rollup.config.mjs b/rollup.config.mjs index d35b8c42..8afbc006 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,17 +1,27 @@ import typescript from 'rollup-plugin-typescript2' +import analyze from 'rollup-plugin-analyzer' +import { terser } from 'rollup-plugin-terser' import del from 'rollup-plugin-delete' const isDevelopmentBuild = process.env.BUILD === 'development' export default { input: 'src/index.ts', - output: { - dir: 'lib', - format: 'cjs', - sourcemap: !!isDevelopmentBuild, - preserveModules: true, - preserveModulesRoot: 'src' - }, + 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 })] + } + ], external: ['async_hooks', 'cluster', 'events', 'worker_threads'], plugins: [ typescript({ @@ -20,7 +30,8 @@ export default { : 'tsconfig.json' }), del({ - targets: 'lib/*' - }) + targets: ['lib/*', 'lib.min/*'] + }), + isDevelopmentBuild && analyze() ] } -- 2.34.1