Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add size-limit bundle size analysis tool #705

Merged
merged 12 commits into from
Aug 29, 2020
3 changes: 0 additions & 3 deletions src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ export async function createRollupConfig(
'process.env.NODE_ENV': JSON.stringify(opts.env),
}),
sourceMaps(),
// sizeSnapshot({
// printInfo: false,
// }),
shouldMinify &&
terser({
sourcemap: true,
Expand Down
1 change: 0 additions & 1 deletion src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
23 changes: 22 additions & 1 deletion src/templates/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
agilgur5 marked this conversation as resolved.
Show resolved Hide resolved
],
packageJson: {
// name: safeName,
version: '0.1.0',
Expand All @@ -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',
Expand Down
10 changes: 10 additions & 0 deletions src/templates/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
};
};
12 changes: 12 additions & 0 deletions templates/basic/.github/workflows/size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: size
on: [pull_request]
jobs:
size:
runs-on: ubuntu-latest
env:
CI_JOB_NUMBER: 1
Comment on lines +6 to +7
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose of this? I found https://github.com/ai/ci-job-number, but this doesn't run a matrix in any case; there is only one job here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to remember why this was needed 😱 I tried without it and the problem is that size-limit doesn't work properly in the action (it throws an error), so for now is needed. I'll try to investigate more about this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a log of the error? Since this is the only job in this new workflow, making it go first shouldn't be necessary, but maybe the action relies on this variable being specified in order to work

steps:
- uses: actions/checkout@v1
- uses: andresz1/size-limit-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
10 changes: 7 additions & 3 deletions templates/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

[`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

This is the folder structure we set up for you:
Expand Down Expand Up @@ -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 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

Expand Down
12 changes: 12 additions & 0 deletions templates/react-with-storybook/.github/workflows/size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: size
on: [pull_request]
jobs:
size:
runs-on: ubuntu-latest
env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v1
- uses: andresz1/size-limit-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
10 changes: 7 additions & 3 deletions templates/react-with-storybook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions templates/react/.github/workflows/size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: size
on: [pull_request]
jobs:
size:
runs-on: ubuntu-latest
env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v1
- uses: andresz1/size-limit-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
10 changes: 7 additions & 3 deletions templates/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down