Skip to content

Commit d46dc30

Browse files
committed
chore: add size-limit config
- Add [`size-limit`](https://github.com/ai/size-limit) config
1 parent 2283891 commit d46dc30

5 files changed

Lines changed: 1972 additions & 1520 deletions

File tree

.github/workflows/size.yaml

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
name: Bundle Size
22

3-
on: [pull_request]
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
47

58
permissions:
69
contents: read
710
pull-requests: write
811

912
jobs:
10-
build:
11-
name: Check compressed size
13+
size:
14+
name: Check Bundle-Size
1215
runs-on: ubuntu-latest
1316

17+
env:
18+
CI_JOB_NUMBER: 1
1419
steps:
15-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
21+
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
1622
with:
17-
fetch-depth: 1
18-
persist-credentials: false
19-
- uses: preactjs/compressed-size-action@66325aad6443cb7cf89c4bfcd414aea2367cda94 # v2
23+
cache: 'yarn'
24+
check-latest: true
25+
node-version: '24.x'
26+
27+
- name: Install dependencies
28+
run: yarn install
29+
30+
- uses: EskiMojo14/size-limit-action@af0584be5b6cc2d056bd31a314fc2ce9c9c1a929 # v2
31+
id: size
32+
continue-on-error: true
33+
2034
with:
21-
repo-token: '${{ secrets.GITHUB_TOKEN }}'
35+
directory: .
36+
github_token: ${{ secrets.GITHUB_TOKEN }}
37+
build_script: build
38+
package_manager: yarn
39+
size_margin: non-zero
40+
41+
- name: Run size-limit locally
42+
if: ${{ success() && steps.size.outcome == 'failure' }}
43+
run: |
44+
yarn run build
45+
yarn run size

.size-limit.mts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import type { Check, SizeLimitConfig } from 'size-limit'
2+
import type { Configuration } from 'webpack'
3+
import packageJson from './package.json' with { type: 'json' }
4+
5+
/**
6+
* An array of all possible Node environments.
7+
*/
8+
const allNodeEnvs = ['production'] as const
9+
10+
const allPackageEntryPoints = [
11+
'./dist/react-redux.mjs',
12+
] as const satisfies string[]
13+
14+
const peerAndProductionDependencies = Object.keys({
15+
...packageJson.dependencies,
16+
...packageJson.peerDependencies,
17+
} as const)
18+
19+
const sizeLimitConfig: SizeLimitConfig = (
20+
await Promise.all(
21+
allNodeEnvs.flatMap((nodeEnv) => {
22+
const modifyWebpackConfig = (<T extends Configuration>(config?: T): T =>
23+
({
24+
...(config ?? {}),
25+
optimization: {
26+
...config?.optimization,
27+
nodeEnv,
28+
},
29+
}) as T) satisfies Check['modifyWebpackConfig']
30+
31+
return allPackageEntryPoints.map(async (entryPoint, index) => {
32+
const allNamedImports = Object.keys(await import(entryPoint)).filter(
33+
(namedImport) => namedImport !== 'default',
34+
)
35+
36+
const sizeLimitConfigWithDependencies = [
37+
...allNamedImports.map(
38+
(namedImport, namedImportIndex) =>
39+
({
40+
path: entryPoint,
41+
name: `${(index + 1).toString()}-${(namedImportIndex + 1).toString()}. import { ${namedImport} } from '${entryPoint}' ('${nodeEnv}' mode)`,
42+
import: `{ ${namedImport} }`,
43+
modifyWebpackConfig,
44+
}) as const satisfies Check,
45+
),
46+
{
47+
path: entryPoint,
48+
name: `${(index + 1).toString()}-${(allNamedImports.length + 1).toString()}. import * from '${entryPoint}' ('${nodeEnv}' mode)`,
49+
import: '*',
50+
modifyWebpackConfig,
51+
},
52+
{
53+
path: entryPoint,
54+
name: `${(index + 1).toString()}-${(allNamedImports.length + 2).toString()}. import '${entryPoint}' ('${nodeEnv}' mode)`,
55+
modifyWebpackConfig,
56+
},
57+
] as const satisfies SizeLimitConfig
58+
59+
const sizeLimitConfigWithoutDependencies =
60+
sizeLimitConfigWithDependencies.map(
61+
(check) =>
62+
({
63+
...check,
64+
name: `${check.name} (excluding dependencies)`,
65+
ignore: peerAndProductionDependencies,
66+
}) as const satisfies Check,
67+
)
68+
69+
return [
70+
// ...sizeLimitConfigWithDependencies,
71+
...sizeLimitConfigWithoutDependencies,
72+
]
73+
})
74+
}),
75+
)
76+
).flat()
77+
78+
export default sizeLimitConfig

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"test": "vitest --run --typecheck",
4949
"test:watch": "vitest --watch",
5050
"type-tests": "tsc --noEmit -p tsconfig.test.json",
51+
"size": "size-limit --config ${INIT_CWD}/.size-limit.mts",
5152
"coverage": "codecov"
5253
},
5354
"peerDependencies": {
@@ -71,6 +72,8 @@
7172
"@arethetypeswrong/cli": "^0.18.3",
7273
"@microsoft/api-extractor": "^7.47.0",
7374
"@reduxjs/toolkit": "^2.2.5",
75+
"@size-limit/file": "^12.1.0",
76+
"@size-limit/webpack": "^12.1.0",
7477
"@testing-library/dom": "^10.4.0",
7578
"@testing-library/jest-dom": "^6.6.3",
7679
"@testing-library/react": "^16.1.0",
@@ -86,13 +89,15 @@
8689
"eslint-plugin-import": "^2.29.1",
8790
"eslint-plugin-prettier": "^5.1.3",
8891
"eslint-plugin-react": "^7.34.2",
92+
"jiti": "^2.7.0",
8993
"jsdom": "^25.0.1",
9094
"pkg-pr-new": "^0.0.75",
9195
"prettier": "^3.3.3",
9296
"react": "^19.2.0",
9397
"react-dom": "^19.2.0",
9498
"redux": "^5.0.1",
9599
"rimraf": "^6.1.3",
100+
"size-limit": "^12.1.0",
96101
"tsup": "^8.5.1",
97102
"typescript": "^5.8.2",
98103
"typescript-eslint": "^7.12.0",

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"checkJs": true,
99
"rootDir": "."
1010
},
11-
"include": ["."],
11+
"include": ["**/*.*"],
1212
"exclude": ["dist*", "examples", "website"]
1313
}

0 commit comments

Comments
 (0)