From 6a0bea987877f69263d33101ce10c890aa795b1f Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Fri, 1 May 2020 13:53:06 +0200 Subject: [PATCH 01/11] Add size-limit and size-limit-action by default --- src/templates/basic.ts | 23 ++++++++++++++++++- src/templates/utils/index.ts | 10 ++++++++ templates/basic/.github/workflows/size.yml | 12 ++++++++++ .../.github/workflows/size.yml | 12 ++++++++++ templates/react/.github/workflows/size.yml | 12 ++++++++++ 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 templates/basic/.github/workflows/size.yml create mode 100644 templates/react-with-storybook/.github/workflows/size.yml create mode 100644 templates/react/.github/workflows/size.yml diff --git a/src/templates/basic.ts b/src/templates/basic.ts index baee6131a..7d077e353 100644 --- a/src/templates/basic.ts +++ b/src/templates/basic.ts @@ -2,7 +2,14 @@ import { Template } from './template'; const basicTemplate: Template = { name: 'basic', - dependencies: ['husky', 'tsdx', 'tslib', 'typescript'], + dependencies: [ + 'husky', + 'tsdx', + 'tslib', + 'typescript', + 'size-limit', + '@size-limit/preset-small-lib', + ], packageJson: { // name: safeName, version: '0.1.0', @@ -21,8 +28,22 @@ const basicTemplate: Template = { test: 'tsdx test', lint: 'tsdx lint', prepare: 'tsdx build', + size: 'size-limit', + analyze: 'size-limit --why', }, peerDependencies: {}, + /* + 'size-limit': [ + { + path: `dist/${safeName}.cjs.production.min.js`, + limit: '10 KB', + }, + { + path: `dist/${safeName}.esm.js`, + limit: '10 KB', + }, + ], + */ husky: { hooks: { 'pre-commit': 'tsdx lint', diff --git a/src/templates/utils/index.ts b/src/templates/utils/index.ts index 4e50eeab6..4f157a077 100644 --- a/src/templates/utils/index.ts +++ b/src/templates/utils/index.ts @@ -13,5 +13,15 @@ export const composePackageJson = (template: Template) => ({ name, author, module: `dist/${name}.esm.js`, + 'size-limit': [ + { + path: `dist/${name}.cjs.production.min.js`, + limit: '10 KB', + }, + { + path: `dist/${name}.esm.js`, + limit: '10 KB', + }, + ], }; }; diff --git a/templates/basic/.github/workflows/size.yml b/templates/basic/.github/workflows/size.yml new file mode 100644 index 000000000..05dd95218 --- /dev/null +++ b/templates/basic/.github/workflows/size.yml @@ -0,0 +1,12 @@ +name: size +on: [pull_request] +jobs: + size: + runs-on: ubuntu-latest + env: + CI_JOB_NUMBER: 1 + steps: + - uses: actions/checkout@v2 + - uses: andresz1/size-limit-action@v1.2.2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/templates/react-with-storybook/.github/workflows/size.yml b/templates/react-with-storybook/.github/workflows/size.yml new file mode 100644 index 000000000..05dd95218 --- /dev/null +++ b/templates/react-with-storybook/.github/workflows/size.yml @@ -0,0 +1,12 @@ +name: size +on: [pull_request] +jobs: + size: + runs-on: ubuntu-latest + env: + CI_JOB_NUMBER: 1 + steps: + - uses: actions/checkout@v2 + - uses: andresz1/size-limit-action@v1.2.2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/templates/react/.github/workflows/size.yml b/templates/react/.github/workflows/size.yml new file mode 100644 index 000000000..05dd95218 --- /dev/null +++ b/templates/react/.github/workflows/size.yml @@ -0,0 +1,12 @@ +name: size +on: [pull_request] +jobs: + size: + runs-on: ubuntu-latest + env: + CI_JOB_NUMBER: 1 + steps: + - uses: actions/checkout@v2 + - uses: andresz1/size-limit-action@v1.2.2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From c9567c14f048205abdc755d47fc5fd72222ba653 Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Fri, 1 May 2020 16:00:56 +0200 Subject: [PATCH 02/11] Upgrade size-limit-action version --- templates/basic/.github/workflows/size.yml | 13 ++++++++----- .../react-with-storybook/.github/workflows/size.yml | 13 ++++++++----- templates/react/.github/workflows/size.yml | 13 ++++++++----- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/templates/basic/.github/workflows/size.yml b/templates/basic/.github/workflows/size.yml index 05dd95218..d46e193bf 100644 --- a/templates/basic/.github/workflows/size.yml +++ b/templates/basic/.github/workflows/size.yml @@ -1,12 +1,15 @@ -name: size -on: [pull_request] +name: "size" +on: + pull_request: + branches: + - master jobs: size: runs-on: ubuntu-latest env: CI_JOB_NUMBER: 1 steps: - - uses: actions/checkout@v2 - - uses: andresz1/size-limit-action@v1.2.2 + - uses: actions/checkout@v1 + - uses: andresz1/size-limit-action@v1.3.0 with: - github_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/templates/react-with-storybook/.github/workflows/size.yml b/templates/react-with-storybook/.github/workflows/size.yml index 05dd95218..d46e193bf 100644 --- a/templates/react-with-storybook/.github/workflows/size.yml +++ b/templates/react-with-storybook/.github/workflows/size.yml @@ -1,12 +1,15 @@ -name: size -on: [pull_request] +name: "size" +on: + pull_request: + branches: + - master jobs: size: runs-on: ubuntu-latest env: CI_JOB_NUMBER: 1 steps: - - uses: actions/checkout@v2 - - uses: andresz1/size-limit-action@v1.2.2 + - uses: actions/checkout@v1 + - uses: andresz1/size-limit-action@v1.3.0 with: - github_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/templates/react/.github/workflows/size.yml b/templates/react/.github/workflows/size.yml index 05dd95218..d46e193bf 100644 --- a/templates/react/.github/workflows/size.yml +++ b/templates/react/.github/workflows/size.yml @@ -1,12 +1,15 @@ -name: size -on: [pull_request] +name: "size" +on: + pull_request: + branches: + - master jobs: size: runs-on: ubuntu-latest env: CI_JOB_NUMBER: 1 steps: - - uses: actions/checkout@v2 - - uses: andresz1/size-limit-action@v1.2.2 + - uses: actions/checkout@v1 + - uses: andresz1/size-limit-action@v1.3.0 with: - github_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + github_token: ${{ secrets.GITHUB_TOKEN }} From e76ef469d3b5b780f74ceb16c503cd6a717a4745 Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Thu, 30 Jul 2020 21:51:54 +0200 Subject: [PATCH 03/11] Update templates/basic/.github/workflows/size.yml Co-authored-by: Anton Gilgur --- templates/basic/.github/workflows/size.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/templates/basic/.github/workflows/size.yml b/templates/basic/.github/workflows/size.yml index d46e193bf..42fff2264 100644 --- a/templates/basic/.github/workflows/size.yml +++ b/templates/basic/.github/workflows/size.yml @@ -1,8 +1,5 @@ name: "size" -on: - pull_request: - branches: - - master +on: [pull_request] jobs: size: runs-on: ubuntu-latest From 064bc7b0c69ab57a2f5b4d965097d87a326a76c4 Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Thu, 30 Jul 2020 21:52:02 +0200 Subject: [PATCH 04/11] Update templates/basic/.github/workflows/size.yml Co-authored-by: Anton Gilgur --- templates/basic/.github/workflows/size.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/basic/.github/workflows/size.yml b/templates/basic/.github/workflows/size.yml index 42fff2264..ae3f76087 100644 --- a/templates/basic/.github/workflows/size.yml +++ b/templates/basic/.github/workflows/size.yml @@ -1,4 +1,4 @@ -name: "size" +name: size on: [pull_request] jobs: size: From a9d4708b9c3e7140a4bbb1001c834874fb208211 Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Thu, 30 Jul 2020 22:59:32 +0200 Subject: [PATCH 05/11] Add documentation in the README.md templates --- templates/basic/README.md | 10 +++++++--- templates/react-with-storybook/README.md | 10 +++++++--- templates/react/README.md | 10 +++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/templates/basic/README.md b/templates/basic/README.md index c3d865fa5..3436b80e6 100644 --- a/templates/basic/README.md +++ b/templates/basic/README.md @@ -30,6 +30,10 @@ Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adju Jest tests are set up to run with `npm test` or `yarn test`. +### Bundle analysis + +Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`. + #### Setup Files This is the folder structure we set up for you: @@ -57,10 +61,10 @@ TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rol ### GitHub Actions -A simple action is included that runs these steps on all pushes: +Two actions are added by default: -- Installs deps w/ cache -- Lints, tests, and builds +- `main` which runs installs deps w/ cache, lints, tests, and builds on all pushes +- `size` which comments cost comparison of your library on every pull request using [size-limit](https://github.com/ai/size-limit) ## Optimizations diff --git a/templates/react-with-storybook/README.md b/templates/react-with-storybook/README.md index be3a99082..b4aaa3d18 100644 --- a/templates/react-with-storybook/README.md +++ b/templates/react-with-storybook/README.md @@ -56,6 +56,10 @@ Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adju Jest tests are set up to run with `npm test` or `yarn test`. +### Bundle analysis + +Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`. + #### Setup Files This is the folder structure we set up for you: @@ -92,10 +96,10 @@ TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rol ### GitHub Actions -A simple action is included that runs these steps on all pushes: +Two actions are added by default: -- Installs deps w/ cache -- Lints, tests, and builds +- `main` which runs installs deps w/ cache, lints, tests, and builds on all pushes +- `size` which comments cost comparison of your library on every pull request using [size-limit](https://github.com/ai/size-limit) ## Optimizations diff --git a/templates/react/README.md b/templates/react/README.md index cdb1f9d45..1f020dd28 100644 --- a/templates/react/README.md +++ b/templates/react/README.md @@ -40,6 +40,10 @@ Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adju Jest tests are set up to run with `npm test` or `yarn test`. +### Bundle analysis + +Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`. + #### Setup Files This is the folder structure we set up for you: @@ -76,10 +80,10 @@ TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rol ### GitHub Actions -A simple action is included that runs these steps on all pushes: +Two actions are added by default: -- Installs deps w/ cache -- Lints, tests, and builds +- `main` which runs installs deps w/ cache, lints, tests, and builds on all pushes +- `size` which comments cost comparison of your library on every pull request using ## Optimizations From 73a356eb03431284b5f4ddd007b429bb8a12bfca Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Thu, 30 Jul 2020 23:00:33 +0200 Subject: [PATCH 06/11] Update size.yml files with given reviews --- templates/basic/.github/workflows/size.yml | 2 +- .../react-with-storybook/.github/workflows/size.yml | 9 +++------ templates/react/.github/workflows/size.yml | 9 +++------ 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/templates/basic/.github/workflows/size.yml b/templates/basic/.github/workflows/size.yml index ae3f76087..5717bc050 100644 --- a/templates/basic/.github/workflows/size.yml +++ b/templates/basic/.github/workflows/size.yml @@ -7,6 +7,6 @@ jobs: CI_JOB_NUMBER: 1 steps: - uses: actions/checkout@v1 - - uses: andresz1/size-limit-action@v1.3.0 + - uses: andresz1/size-limit-action@v1.4.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/templates/react-with-storybook/.github/workflows/size.yml b/templates/react-with-storybook/.github/workflows/size.yml index d46e193bf..5717bc050 100644 --- a/templates/react-with-storybook/.github/workflows/size.yml +++ b/templates/react-with-storybook/.github/workflows/size.yml @@ -1,8 +1,5 @@ -name: "size" -on: - pull_request: - branches: - - master +name: size +on: [pull_request] jobs: size: runs-on: ubuntu-latest @@ -10,6 +7,6 @@ jobs: CI_JOB_NUMBER: 1 steps: - uses: actions/checkout@v1 - - uses: andresz1/size-limit-action@v1.3.0 + - uses: andresz1/size-limit-action@v1.4.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/templates/react/.github/workflows/size.yml b/templates/react/.github/workflows/size.yml index d46e193bf..5717bc050 100644 --- a/templates/react/.github/workflows/size.yml +++ b/templates/react/.github/workflows/size.yml @@ -1,8 +1,5 @@ -name: "size" -on: - pull_request: - branches: - - master +name: size +on: [pull_request] jobs: size: runs-on: ubuntu-latest @@ -10,6 +7,6 @@ jobs: CI_JOB_NUMBER: 1 steps: - uses: actions/checkout@v1 - - uses: andresz1/size-limit-action@v1.3.0 + - uses: andresz1/size-limit-action@v1.4.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} From ce6f47e78b70924ab16a9c407b9006b52868693f Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Thu, 30 Jul 2020 23:04:55 +0200 Subject: [PATCH 07/11] Remove rollup-plugin-size-snapshot --- src/createRollupConfig.ts | 3 --- src/env.d.ts | 1 - 2 files changed, 4 deletions(-) diff --git a/src/createRollupConfig.ts b/src/createRollupConfig.ts index cd310f5d5..5cb3ab6a3 100644 --- a/src/createRollupConfig.ts +++ b/src/createRollupConfig.ts @@ -194,9 +194,6 @@ export async function createRollupConfig( 'process.env.NODE_ENV': JSON.stringify(opts.env), }), sourceMaps(), - // sizeSnapshot({ - // printInfo: false, - // }), shouldMinify && terser({ sourcemap: true, diff --git a/src/env.d.ts b/src/env.d.ts index 0ee8339e0..0785badc2 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -12,7 +12,6 @@ declare module '@babel/core' { // Rollup plugins declare module 'rollup-plugin-babel'; -declare module 'rollup-plugin-size-snapshot'; declare module 'rollup-plugin-terser'; declare module 'babel-traverse'; declare module 'babylon'; From b4b8094e6bbe4f21207f29fb6c329316e72cd103 Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Tue, 25 Aug 2020 22:22:08 +0200 Subject: [PATCH 08/11] Update templates/basic/README.md Co-authored-by: Anton Gilgur --- templates/basic/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/basic/README.md b/templates/basic/README.md index 3436b80e6..bd33c8035 100644 --- a/templates/basic/README.md +++ b/templates/basic/README.md @@ -30,9 +30,9 @@ Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adju Jest tests are set up to run with `npm test` or `yarn test`. -### Bundle analysis +### Bundle Analysis -Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`. +[`size-limit`](https://github.com/ai/size-limit) is set up to calculate the real cost of your library with `npm run size` and visualize the bundle with `npm run analyze`. #### Setup Files From 3f1156b5172a834b32505343819c8da763b141d0 Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Tue, 25 Aug 2020 22:22:20 +0200 Subject: [PATCH 09/11] Update templates/basic/README.md Co-authored-by: Anton Gilgur --- templates/basic/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/basic/README.md b/templates/basic/README.md index bd33c8035..934945c92 100644 --- a/templates/basic/README.md +++ b/templates/basic/README.md @@ -63,7 +63,7 @@ TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rol Two actions are added by default: -- `main` which runs installs deps w/ cache, lints, tests, and builds on all pushes +- `main` which installs deps w/ cache, lints, tests, and builds on all pushes - `size` which comments cost comparison of your library on every pull request using [size-limit](https://github.com/ai/size-limit) ## Optimizations From 49e379f7ce282b463f9a40d224771409578a8b8a Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Tue, 25 Aug 2020 22:22:30 +0200 Subject: [PATCH 10/11] Update templates/basic/README.md Co-authored-by: Anton Gilgur --- templates/basic/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/basic/README.md b/templates/basic/README.md index 934945c92..0e115bfd2 100644 --- a/templates/basic/README.md +++ b/templates/basic/README.md @@ -64,7 +64,7 @@ TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rol Two actions are added by default: - `main` which installs deps w/ cache, lints, tests, and builds on all pushes -- `size` which comments cost comparison of your library on every pull request using [size-limit](https://github.com/ai/size-limit) +- `size` which comments cost comparison of your library on every pull request using [`size-limit`](https://github.com/ai/size-limit) ## Optimizations From f7f5bfd5f99297135b3f042e165517971d196302 Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Tue, 25 Aug 2020 23:07:23 +0200 Subject: [PATCH 11/11] Update size-limit-action version --- templates/basic/.github/workflows/size.yml | 2 +- templates/react-with-storybook/.github/workflows/size.yml | 2 +- templates/react/.github/workflows/size.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/basic/.github/workflows/size.yml b/templates/basic/.github/workflows/size.yml index 5717bc050..6021cda3e 100644 --- a/templates/basic/.github/workflows/size.yml +++ b/templates/basic/.github/workflows/size.yml @@ -7,6 +7,6 @@ jobs: CI_JOB_NUMBER: 1 steps: - uses: actions/checkout@v1 - - uses: andresz1/size-limit-action@v1.4.0 + - uses: andresz1/size-limit-action@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/templates/react-with-storybook/.github/workflows/size.yml b/templates/react-with-storybook/.github/workflows/size.yml index 5717bc050..6021cda3e 100644 --- a/templates/react-with-storybook/.github/workflows/size.yml +++ b/templates/react-with-storybook/.github/workflows/size.yml @@ -7,6 +7,6 @@ jobs: CI_JOB_NUMBER: 1 steps: - uses: actions/checkout@v1 - - uses: andresz1/size-limit-action@v1.4.0 + - uses: andresz1/size-limit-action@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/templates/react/.github/workflows/size.yml b/templates/react/.github/workflows/size.yml index 5717bc050..6021cda3e 100644 --- a/templates/react/.github/workflows/size.yml +++ b/templates/react/.github/workflows/size.yml @@ -7,6 +7,6 @@ jobs: CI_JOB_NUMBER: 1 steps: - uses: actions/checkout@v1 - - uses: andresz1/size-limit-action@v1.4.0 + - uses: andresz1/size-limit-action@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }}