Skip to content

Commit

Permalink
feat: add size-limit bundle size analysis tool to templates (jaredpal…
Browse files Browse the repository at this point in the history
…mer#705)

- Add size-limit and size-limit-action to all templates
  - Use `@size-limit/preset-small-lib` by default
  - Add `yarn size` and `yarn visualize` scripts

- Remove outdated references to rollup-plugin-size-snapshot

Co-authored-by: Anton Gilgur <[email protected]>
  • Loading branch information
2 people authored and paul-vd committed Dec 1, 2020
1 parent 6851815 commit bac0716
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 14 deletions.
3 changes: 0 additions & 3 deletions src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,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',
],
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
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 @@ -97,10 +101,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

0 comments on commit bac0716

Please sign in to comment.