From b02a3f887fba5d203c0ddfb7a380412beed87077 Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Thu, 26 Dec 2019 18:13:37 +0200 Subject: [PATCH] typescript(option): build: edited the rollup config to read paths from package.json and show the filesize of the esm bundle Signed-off-by: prescientmoon --- typescript/option/README.md | 2 +- typescript/option/package.json | 2 + typescript/option/pnpm-lock.yaml | 107 +++++++++++++++++++++++++++++ typescript/option/rollup.config.ts | 17 +++-- typescript/option/tsconfig.json | 6 +- 5 files changed, 125 insertions(+), 9 deletions(-) diff --git a/typescript/option/README.md b/typescript/option/README.md index 658cd54..5e5486f 100644 --- a/typescript/option/README.md +++ b/typescript/option/README.md @@ -41,7 +41,7 @@ Both limitaions bellow come from the lack of nominal-typing offered by TypeScrip npm install @adrielus/option ``` -(There is also an amd build at `/dist/bundle.amd.js` which uses the `Option` namespace) +(There is also an amd build at `/dist/bundle.umd.js` which uses the `Option` namespace) ## Usage diff --git a/typescript/option/package.json b/typescript/option/package.json index 0e2dbd1..dbbbf11 100644 --- a/typescript/option/package.json +++ b/typescript/option/package.json @@ -5,6 +5,7 @@ "main": "dist/bundle.cjs.js", "module": "dist/index.esm.js", "typings": "dist/index.esm.d.ts", + "browser": "dist/bundle.umd.js", "scripts": { "prebuild": "rimraf dist", "build": "rollup -c rollup.config.ts", @@ -50,6 +51,7 @@ "mocha": "^6.2.2", "rimraf": "^3.0.0", "rollup": "^1.27.14", + "rollup-plugin-filesize": "^6.2.1", "rollup-plugin-terser": "^5.1.3", "semantic-release": "^15.14.0", "sinon": "^8.0.1", diff --git a/typescript/option/pnpm-lock.yaml b/typescript/option/pnpm-lock.yaml index e5d1f82..a1c5047 100644 --- a/typescript/option/pnpm-lock.yaml +++ b/typescript/option/pnpm-lock.yaml @@ -13,6 +13,7 @@ devDependencies: mocha: 6.2.2 rimraf: 3.0.0 rollup: 1.27.14 + rollup-plugin-filesize: 6.2.1 rollup-plugin-terser: 5.1.3_rollup@1.27.14 semantic-release: 15.14.0_semantic-release@15.14.0 sinon: 8.0.1 @@ -1174,6 +1175,12 @@ packages: node: '>=8' resolution: integrity: sha512-quoaXsZ9/BLNae5yiNoUz+Nhkwz83GhWwtYFglcjEQB2NDHCIpApbqXxIFnm4Pq/Nvhrsq5sYJFyohrrxnTGAA== + /ansi-align/3.0.0: + dependencies: + string-width: 3.1.0 + dev: true + resolution: + integrity: sha512-ZpClVKqXN3RGBmKibdfWzqCY4lnjEuoNzU5T0oEFpfd/z5qJHVarukridD4juLO2FXMiwUQxr9WqQtaYa8XRYw== /ansi-colors/3.2.3: dev: true engines: @@ -1291,6 +1298,21 @@ packages: dev: true resolution: integrity: sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw== + /boxen/4.2.0: + dependencies: + ansi-align: 3.0.0 + camelcase: 5.3.1 + chalk: 3.0.0 + cli-boxes: 2.2.0 + string-width: 4.2.0 + term-size: 2.1.1 + type-fest: 0.8.1 + widest-line: 3.1.0 + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-eB4uT9RGzg2odpER62bBwSLvUeGC+WbRjjyyFhGsKnc8wp/m0+hQsMUvUe3H2V0D5vw0nBdO1hCJoZo5mKeuIQ== /brace-expansion/1.1.11: dependencies: balanced-match: 1.0.0 @@ -1306,6 +1328,14 @@ packages: node: '>=8' resolution: integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== + /brotli-size/4.0.0: + dependencies: + duplexer: 0.1.1 + dev: true + engines: + node: '>= 10.16.0' + resolution: + integrity: sha512-uA9fOtlTRC0iqKfzff1W34DXUA3GyVqbUaeo3Rw3d4gd1eavKVCETXrn3NzO74W+UVkG3UHu8WxUi+XvKI/huA== /browser-stdout/1.3.1: dev: true resolution: @@ -1405,6 +1435,15 @@ packages: node: '>=4' resolution: integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== + /chalk/3.0.0: + dependencies: + ansi-styles: 4.2.0 + supports-color: 7.1.0 + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg== /check-error/1.0.2: dev: true resolution: @@ -1415,6 +1454,12 @@ packages: node: '>=6' resolution: integrity: sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A== + /cli-boxes/2.2.0: + dev: true + engines: + node: '>=6' + resolution: + integrity: sha512-gpaBrMAizVEANOpfZp/EEUixTXDyGt7DFzdK5hU+UbWt/J0lB0w20ncZj59Z9a93xHb9u12zF5BS6i9RKbtg4w== /cli-table/0.3.1: dependencies: colors: 1.0.3 @@ -1467,6 +1512,12 @@ packages: node: '>=0.1.90' resolution: integrity: sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs= + /colors/1.4.0: + dev: true + engines: + node: '>=0.1.90' + resolution: + integrity: sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== /commander/2.20.3: dev: true resolution: @@ -1689,6 +1740,10 @@ packages: node: '>=0.10.0' resolution: integrity: sha1-G3CK8JSknJoOfbyteQq6U52sEXc= + /duplexer/0.1.1: + dev: true + resolution: + integrity: sha1-rOb/gIwc5mtX0ev5eXessCM0z8E= /duplexer2/0.1.4: dependencies: readable-stream: 2.3.6 @@ -1858,6 +1913,12 @@ packages: node: '>=8' resolution: integrity: sha512-ravh8VRXqHuMvZt/d8GblBeqDMkdJMBdv/2KntFH+ra5MXkO7nxNKpzQ3n6QD/2da1kH0aWmNISdvhM7gl2gVg== + /filesize/4.2.1: + dev: true + engines: + node: '>= 0.4.0' + resolution: + integrity: sha512-bP82Hi8VRZX/TUBKfE24iiUGsB/sfm2WUrwTQyAzQrhO3V9IhcBBNBXMyzLY5orACxRyYJ3d2HeRVX+eFv4lmA== /fill-range/7.0.1: dependencies: to-regex-range: 5.0.1 @@ -2029,6 +2090,15 @@ packages: node: '>=4.x' resolution: integrity: sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA== + /gzip-size/5.1.1: + dependencies: + duplexer: 0.1.1 + pify: 4.0.1 + dev: true + engines: + node: '>=6' + resolution: + integrity: sha512-FNHi6mmoHvs1mxZAds4PpdCS6QG8B4C1krxJsMutgxl5t3+GlRTzzI3NEkifXx2pVsOvJdOGSmIgDhQ55FwdPA== /handlebars/4.5.3: dependencies: neo-async: 2.6.1 @@ -2477,6 +2547,10 @@ packages: dev: true resolution: integrity: sha1-1SfftUVuynzJu5XV2ur4i6VKVFE= + /lodash.merge/4.6.2: + dev: true + resolution: + integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== /lodash.set/4.3.2: dev: true resolution: @@ -3196,6 +3270,12 @@ packages: node: '>=4' resolution: integrity: sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY= + /pify/4.0.1: + dev: true + engines: + node: '>=6' + resolution: + integrity: sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g== /pkg-conf/2.1.0: dependencies: find-up: 2.1.0 @@ -3425,6 +3505,18 @@ packages: hasBin: true resolution: integrity: sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg== + /rollup-plugin-filesize/6.2.1: + dependencies: + boxen: 4.2.0 + brotli-size: 4.0.0 + colors: 1.4.0 + filesize: 4.2.1 + gzip-size: 5.1.1 + lodash.merge: 4.6.2 + terser: 4.4.3 + dev: true + resolution: + integrity: sha512-JQ2+NMoka81lCR2caGWyngqMKpvJCl7EkFYU7A+T0dA7U1Aml13FW5Ky0aiZIeU3/13cjsKQLRr35SQVmk6i/A== /rollup-plugin-terser/5.1.3_rollup@1.27.14: dependencies: '@babel/code-frame': 7.5.5 @@ -3838,6 +3930,12 @@ packages: node: '>=8' resolution: integrity: sha512-WrH/pui8YCwmeiAoxV+lpRH9HpRtgBhSR2ViBPgpGb/wnYDzp21R4MN45fsCGvLROvY67o3byhJRYRONJyImVQ== + /term-size/2.1.1: + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-UqvQSch04R+69g4RDhrslmGvGL3ucDRX/U+snYW0Mab4uCAyKSndUksaoqlJ81QKSpRnIsuOYQCbC2ZWx2896A== /terser/4.4.3: dependencies: commander: 2.20.3 @@ -4061,6 +4159,14 @@ packages: dev: true resolution: integrity: sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA== + /widest-line/3.1.0: + dependencies: + string-width: 4.2.0 + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg== /windows-release/3.2.0: dependencies: execa: 1.0.0 @@ -4201,6 +4307,7 @@ specifiers: mocha: ^6.2.2 rimraf: ^3.0.0 rollup: ^1.27.14 + rollup-plugin-filesize: ^6.2.1 rollup-plugin-terser: ^5.1.3 semantic-release: ^15.14.0 sinon: ^8.0.1 diff --git a/typescript/option/rollup.config.ts b/typescript/option/rollup.config.ts index 3e67884..d31b128 100644 --- a/typescript/option/rollup.config.ts +++ b/typescript/option/rollup.config.ts @@ -3,27 +3,29 @@ import { resolve } from 'path' import ts from '@wessberg/rollup-plugin-ts' import nodeResolve from '@rollup/plugin-node-resolve' import commonjs from '@rollup/plugin-commonjs' +import _package from './package.json' +import filesize from 'rollup-plugin-filesize' const outputDirectory = resolve(__dirname, 'dist') const inputFile = resolve(__dirname, 'src/index.ts') const dev = Boolean(process.env.ROLLUP_WATCH) -const commonPlugins = [commonjs(), nodeResolve()] +const commonPlugins = [nodeResolve(), commonjs()] export default [ { input: inputFile, output: [ { - file: `${outputDirectory}/index.cjs.js`, + file: _package.main, format: 'cjs', sourcemap: true }, { - file: `${outputDirectory}/index.amd.js`, + file: _package.browser, sourcemap: true, - format: 'amd', + format: 'umd', name: 'Option' } ], @@ -33,7 +35,7 @@ export default [ input: inputFile, output: [ { - file: `${outputDirectory}/index.esm.js`, + file: _package.module, format: 'esm', sourcemap: true } @@ -48,7 +50,10 @@ export default [ ] } }), - !dev && terser() + !dev && terser(), + filesize({ + showBrotliSize: true + }) ] } ] diff --git a/typescript/option/tsconfig.json b/typescript/option/tsconfig.json index 6e4fb37..2e31f4d 100644 --- a/typescript/option/tsconfig.json +++ b/typescript/option/tsconfig.json @@ -6,8 +6,10 @@ "strictNullChecks": true, "sourceMap": true, "downlevelIteration": true, - "target": "es6" + "target": "es6", + + "resolveJsonModule": true }, - "include": ["src", "sandbox", "test"], + "include": ["src", "sandbox", "test", "package.json"], "exclude": ["dist"] }