Skip to content

Commit eca6d10

Browse files
committed
update size limit config and re-enable action
1 parent 0ffabd9 commit eca6d10

File tree

2 files changed

+57
-18
lines changed

2 files changed

+57
-18
lines changed
File renamed without changes.

packages/toolkit/.size-limit.js renamed to packages/toolkit/.size-limit.cjs

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
const webpack = require('webpack')
22
let { join } = require('path')
33

4-
const suffixes = ['cjs.production.min.js', 'esm.js']
4+
const esmSuffixes = ['modern.mjs', 'browser.mjs', 'legacy-esm.js']
5+
const cjsSuffixes = ['development.cjs', 'production.min.cjs']
56

6-
function withRtkPath(suffix) {
7+
function withRtkPath(suffix, cjs = false) {
8+
/**
9+
* @param {webpack.Configuration} config
10+
*/
711
return (config) => {
812
config.plugins.push(
913
new webpack.NormalModuleReplacementPlugin(
@@ -14,6 +18,10 @@ function withRtkPath(suffix) {
1418
/@reduxjs\/toolkit\/query/,
1519
join(__dirname, `query`)
1620
),
21+
new webpack.NormalModuleReplacementPlugin(
22+
/@reduxjs\/toolkit\/react/,
23+
join(__dirname, 'react')
24+
),
1725
new webpack.NormalModuleReplacementPlugin(
1826
/@reduxjs\/toolkit/,
1927
join(__dirname)
@@ -24,7 +32,7 @@ function withRtkPath(suffix) {
2432
const old = r.request
2533
r.request = r.request.replace(
2634
/rtk-query-react.modern.js$/,
27-
`rtk-query-react.${suffix}`
35+
`${cjs ? 'cjs/' : ''}rtk-query-react.${suffix}`
2836
)
2937
// console.log(old, '=>', r.request)
3038
}
@@ -33,26 +41,37 @@ function withRtkPath(suffix) {
3341
const old = r.request
3442
r.request = r.request.replace(
3543
/rtk-query.modern.js$/,
36-
`rtk-query.${suffix}`
44+
`${cjs ? 'cjs/' : ''}rtk-query.${suffix}`
3745
)
3846
// console.log(old, '=>', r.request)
3947
}),
48+
new webpack.NormalModuleReplacementPlugin(
49+
/redux-toolkit-react.modern.js$/,
50+
(r) => {
51+
const old = r.request
52+
r.request = r.request.replace(
53+
/redux-toolkit-react.modern.js$/,
54+
`${cjs ? 'cjs/' : ''}redux-toolkit-react.${suffix}`
55+
)
56+
// console.log(old, '=>', r.request)
57+
}
58+
),
4059
new webpack.NormalModuleReplacementPlugin(
4160
/redux-toolkit.modern.js$/,
4261
(r) => {
4362
const old = r.request
4463
r.request = r.request.replace(
4564
/redux-toolkit.modern.js$/,
46-
`redux-toolkit.${suffix}`
65+
`${cjs ? 'cjs/' : ''}redux-toolkit.${suffix}`
4766
)
4867
// console.log(old, '=>', r.request)
4968
}
5069
)
5170
)
52-
if (suffix === 'cjs.production.min.js') {
53-
config.resolve.mainFields = ['main', 'module']
71+
if (suffix === 'production.min.cjs') {
72+
;(config.resolve ??= {}).mainFields = ['main', 'module']
5473
}
55-
config.optimization.nodeEnv = 'production'
74+
;(config.optimization ??= {}).nodeEnv = 'production'
5675
return config
5776
}
5877
}
@@ -66,42 +85,62 @@ const ignoreAll = [
6685
'redux-thunk',
6786
]
6887

69-
module.exports = [
88+
const entryPoints = [
7089
{
7190
name: `1. entry point: @reduxjs/toolkit`,
72-
path: 'dist/redux-toolkit.modern.js',
91+
path: 'dist/redux-toolkit.modern.mjs',
92+
},
93+
{
94+
name: `1. entry point: @reduxjs/toolkit/react`,
95+
path: 'dist/react/redux-toolkit-react.modern.mjs',
7396
},
7497
{
7598
name: `1. entry point: @reduxjs/toolkit/query`,
76-
path: 'dist/query/rtk-query.modern.js',
99+
path: 'dist/query/rtk-query.modern.mjs',
77100
},
78101
{
79102
name: `1. entry point: @reduxjs/toolkit/query/react`,
80-
path: 'dist/query/react/rtk-query-react.modern.js',
103+
path: 'dist/query/react/rtk-query-react.modern.mjs',
81104
},
82105
{
83106
name: `2. entry point: @reduxjs/toolkit (without dependencies)`,
84-
path: 'dist/redux-toolkit.modern.js',
107+
path: 'dist/redux-toolkit.modern.mjs',
108+
ignore: ignoreAll,
109+
},
110+
{
111+
name: `2. entry point: @reduxjs/toolkit/react (without dependencies)`,
112+
path: 'dist/react/redux-toolkit-react.modern.mjs',
85113
ignore: ignoreAll,
86114
},
87115
{
88116
name: `2. entry point: @reduxjs/toolkit/query (without dependencies)`,
89-
path: 'dist/query/rtk-query.modern.js',
117+
path: 'dist/query/rtk-query.modern.mjs',
90118
ignore: ignoreAll,
91119
},
92120
{
93121
name: `2. entry point: @reduxjs/toolkit/query/react (without dependencies)`,
94-
path: 'dist/query/react/rtk-query-react.modern.js',
122+
path: 'dist/query/react/rtk-query-react.modern.mjs',
95123
ignore: ignoreAll,
96124
},
97125
]
126+
127+
module.exports = entryPoints
98128
.flatMap((e) =>
99-
suffixes.map((suffix) => ({
129+
esmSuffixes.map((suffix) => ({
100130
...e,
101131
name: e.name + ` (${suffix})`,
102132
modifyWebpackConfig: withRtkPath(suffix),
103133
}))
104134
)
135+
.concat(
136+
entryPoints.flatMap((e) =>
137+
cjsSuffixes.map((suffix) => ({
138+
...e,
139+
name: e.name + ` (cjs, ${suffix})`,
140+
modifyWebpackConfig: withRtkPath(suffix, true),
141+
}))
142+
)
143+
)
105144
.concat(
106145
...[
107146
{
@@ -138,7 +177,7 @@ module.exports = [
138177
},
139178
].map((e) => ({
140179
...e,
141-
name: e.name + ` (esm.js)`,
142-
modifyWebpackConfig: withRtkPath('esm.js'),
180+
name: e.name + ` (.modern.mjs)`,
181+
modifyWebpackConfig: withRtkPath('.modern.mjs'),
143182
}))
144183
)

0 commit comments

Comments
 (0)