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
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',
},
],
};
};
15 changes: 15 additions & 0 deletions templates/basic/.github/workflows/size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "size"
andresz1 marked this conversation as resolved.
Show resolved Hide resolved
on:
pull_request:
branches:
- master
andresz1 marked this conversation as resolved.
Show resolved Hide resolved
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.3.0
andresz1 marked this conversation as resolved.
Show resolved Hide resolved
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
15 changes: 15 additions & 0 deletions templates/react-with-storybook/.github/workflows/size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "size"
on:
pull_request:
branches:
- master
jobs:
size:
runs-on: ubuntu-latest
env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v1
- uses: andresz1/size-limit-action@v1.3.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
15 changes: 15 additions & 0 deletions templates/react/.github/workflows/size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "size"
on:
pull_request:
branches:
- master
jobs:
size:
runs-on: ubuntu-latest
env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v1
- uses: andresz1/size-limit-action@v1.3.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}