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 config #2173

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions .github/workflows/size.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
name: Bundle Size
name: Check Bundle-Size

on: [pull_request]
on: [push, pull_request, workflow_dispatch]

jobs:
build:
name: Check compressed size
size:
runs-on: ubuntu-latest
name: Check Bundle-Size

strategy:
matrix:
node: ['22.x']

env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
fetch-depth: 1
- uses: preactjs/compressed-size-action@v2
node-version: ${{ matrix.node }}
cache: 'yarn'
check-latest: true

- run: yarn install

- uses: EskiMojo14/size-limit-action@v2
id: size
continue-on-error: true

with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
directory: .
github_token: ${{ secrets.GITHUB_TOKEN }}
build_script: build
package_manager: yarn
size_margin: non-zero

- name: Run size-limit locally
if: ${{ success() && steps.size.outcome == 'failure' }}
run: |
yarn run build
yarn run size
64 changes: 64 additions & 0 deletions .size-limit.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type { Check, SizeLimitConfig } from 'size-limit'
import type { Configuration } from 'webpack'
import packageJson from './package.json' with { type: 'json' }

/**
* An array of all possible Node environments.
*/
const allNodeEnvs = ['production'] as const

const allPackageEntryPoints = ['./dist/react-redux.mjs'] as const

const dependencies = Object.keys(packageJson.dependencies ?? {})

const sizeLimitConfig: SizeLimitConfig = (
await Promise.all(
allNodeEnvs.flatMap((nodeEnv) => {
const modifyWebpackConfig = ((config: Configuration) => {
;(config.optimization ??= {}).nodeEnv = nodeEnv

return config
}) satisfies Check['modifyWebpackConfig']

return allPackageEntryPoints.map(async (entryPoint, index) => {
const allNamedImports = Object.keys(await import(entryPoint)).filter(
(namedImport) => namedImport !== 'default',
)

const sizeLimitConfigWithDependencies = allNamedImports
.map<Check>((namedImport, namedImportIndex) => ({
path: entryPoint,
name: `${index + 1}-${namedImportIndex + 1}. import { ${namedImport} } from "${entryPoint}" ('${nodeEnv}' mode)`,
import: `{ ${namedImport} }`,
modifyWebpackConfig,
}))
.concat([
{
path: entryPoint,
name: `${index + 1}-${allNamedImports.length + 1}. import * from "${entryPoint}" ('${nodeEnv}' mode)`,
import: '*',
modifyWebpackConfig,
},
{
path: entryPoint,
name: `${index + 1}-${allNamedImports.length + 2}. import "${entryPoint}" ('${nodeEnv}' mode)`,
modifyWebpackConfig,
},
])

const sizeLimitConfigWithoutDependencies =
sizeLimitConfigWithDependencies.map((check) => ({
...check,
name: `${check.name} (excluding dependencies)`,
ignore: dependencies,
}))

return sizeLimitConfigWithDependencies.concat(
sizeLimitConfigWithoutDependencies,
)
})
}),
)
).flat()

export default sizeLimitConfig
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"test": "vitest --run --typecheck",
"test:watch": "vitest --watch",
"type-tests": "tsc --noEmit -p tsconfig.test.json",
"size": "size-limit --config $INIT_CWD/.size-limit.mts",
"coverage": "codecov"
},
"peerDependencies": {
Expand All @@ -70,10 +71,12 @@
"devDependencies": {
"@microsoft/api-extractor": "^7.47.0",
"@reduxjs/toolkit": "^2.2.5",
"@size-limit/file": "^11.2.0",
"@size-limit/webpack": "^11.2.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
"@types/node": "^20.14.2",
"@types/node": "^22.13.5",
"@types/prop-types": "^15.7.12",
"@types/react": "^19.0.1",
"@types/react-dom": "^19.0.1",
Expand All @@ -91,6 +94,7 @@
"react-dom": "^19.0.0",
"redux": "^5.0.1",
"rimraf": "^5.0.7",
"size-limit": "^11.2.0",
"tsup": "^8.3.5",
"typescript": "^5.5.4",
"typescript-eslint": "^7.12.0",
Expand Down
Loading
Loading