Skip to content
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
37 changes: 29 additions & 8 deletions .github/workflows/size.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
name: Bundle Size

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

permissions:
contents: read
pull-requests: write

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

env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
fetch-depth: 1
persist-credentials: false
- uses: preactjs/compressed-size-action@66325aad6443cb7cf89c4bfcd414aea2367cda94 # v2
cache: 'yarn'
check-latest: true
node-version: '24.x'

- name: Install dependencies
run: yarn install

- uses: EskiMojo14/size-limit-action@af0584be5b6cc2d056bd31a314fc2ce9c9c1a929 # 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
78 changes: 78 additions & 0 deletions .size-limit.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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 satisfies string[]

const peerAndProductionDependencies = Object.keys({
...packageJson.dependencies,
...packageJson.peerDependencies,
} as const)

const sizeLimitConfig: SizeLimitConfig = (
await Promise.all(
allNodeEnvs.flatMap((nodeEnv) => {
const modifyWebpackConfig = (<T extends Configuration>(config?: T): T =>
({
...(config ?? {}),
optimization: {
...config?.optimization,
nodeEnv,
},
}) as T) satisfies Check['modifyWebpackConfig']

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

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

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

return [
// ...sizeLimitConfigWithDependencies,
...sizeLimitConfigWithoutDependencies,
]
})
}),
)
).flat()

export default sizeLimitConfig
5 changes: 5 additions & 0 deletions 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 @@ -71,6 +72,8 @@
"@arethetypeswrong/cli": "^0.18.3",
"@microsoft/api-extractor": "^7.47.0",
"@reduxjs/toolkit": "^2.2.5",
"@size-limit/file": "^12.1.0",
"@size-limit/webpack": "^12.1.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
Expand All @@ -86,12 +89,14 @@
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.2",
"jiti": "^2.7.0",
"jsdom": "^25.0.1",
"prettier": "^3.3.3",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"redux": "^5.0.1",
"rimraf": "^6.1.3",
"size-limit": "^12.1.0",
"tsup": "^8.5.1",
"typescript": "^5.8.2",
"typescript-eslint": "^7.12.0",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"checkJs": true,
"rootDir": "."
},
"include": ["."],
"include": ["**/*.*"],
"exclude": ["dist*", "examples", "website"]
}
Loading
Loading