-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy path.size-limit.mts
69 lines (59 loc) · 2.27 KB
/
.size-limit.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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/redux-toolkit.modern.mjs',
'./dist/react/redux-toolkit-react.modern.mjs',
'./dist/query/rtk-query.modern.mjs',
'./dist/query/react/rtk-query-react.modern.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