From 378e3e07dc8df91b5794b284f94b3468dd68aac5 Mon Sep 17 00:00:00 2001 From: EskiMojo14 Date: Sun, 4 Feb 2024 23:27:23 +0000 Subject: [PATCH] fix entry resolution --- packages/toolkit/.size-limit.cjs | 49 ++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/packages/toolkit/.size-limit.cjs b/packages/toolkit/.size-limit.cjs index 7d49425afc..6d32250744 100644 --- a/packages/toolkit/.size-limit.cjs +++ b/packages/toolkit/.size-limit.cjs @@ -5,6 +5,12 @@ const esmSuffixes = ['modern.mjs', 'browser.mjs', 'legacy-esm.js'] const cjsSuffixes = ['development.cjs', 'production.min.cjs'] function withRtkPath(suffix, cjs = false) { + /** + * @param {string} name + */ + function alias(name) { + return `${cjs ? 'cjs/' : ''}${name}.${suffix}` + } /** * @param {webpack.Configuration} config */ @@ -12,62 +18,63 @@ function withRtkPath(suffix, cjs = false) { config.plugins.push( new webpack.NormalModuleReplacementPlugin( /@reduxjs\/toolkit\/query\/react/, - require.resolve('./query/react'), + join(__dirname, 'dist/query/react/rtk-query-react.modern.mjs'), ), new webpack.NormalModuleReplacementPlugin( /@reduxjs\/toolkit\/query/, - require.resolve('./query'), + join(__dirname, 'dist/query/rtk-query.modern.mjs'), ), new webpack.NormalModuleReplacementPlugin( /@reduxjs\/toolkit\/react/, - require.resolve('./react'), + join(__dirname, 'dist/react/redux-toolkit-react.modern.mjs'), ), new webpack.NormalModuleReplacementPlugin( /@reduxjs\/toolkit/, - require.resolve('.'), + join(__dirname, 'dist/redux-toolkit.modern.mjs'), ), new webpack.NormalModuleReplacementPlugin( - /rtk-query-react.modern.js/, + /rtk-query-react.modern.mjs/, (r) => { const old = r.request r.request = r.request.replace( - /rtk-query-react.modern.js$/, - `${cjs ? 'cjs/' : ''}rtk-query-react.${suffix}`, + /rtk-query-react.modern.mjs$/, + alias('rtk-query-react'), ) - // console.log(old, '=>', r.request) + //console.log(old, '=>', r.request) }, ), - new webpack.NormalModuleReplacementPlugin(/rtk-query.modern.js/, (r) => { + new webpack.NormalModuleReplacementPlugin(/rtk-query.modern.mjs/, (r) => { const old = r.request r.request = r.request.replace( - /rtk-query.modern.js$/, - `${cjs ? 'cjs/' : ''}rtk-query.${suffix}`, + /rtk-query.modern.mjs$/, + alias('rtk-query'), ) - // console.log(old, '=>', r.request) + //console.log(old, '=>', r.request) }), new webpack.NormalModuleReplacementPlugin( - /redux-toolkit-react.modern.js$/, + /redux-toolkit-react.modern.mjs$/, (r) => { const old = r.request r.request = r.request.replace( - /redux-toolkit-react.modern.js$/, - `${cjs ? 'cjs/' : ''}redux-toolkit-react.${suffix}`, + /redux-toolkit-react.modern.mjs$/, + alias('redux-toolkit-react'), ) - // console.log(old, '=>', r.request) + //console.log(old, '=>', r.request) }, ), new webpack.NormalModuleReplacementPlugin( - /redux-toolkit.modern.js$/, + /redux-toolkit.modern.mjs$/, (r) => { const old = r.request r.request = r.request.replace( - /redux-toolkit.modern.js$/, - `${cjs ? 'cjs/' : ''}redux-toolkit.${suffix}`, + /redux-toolkit.modern.mjs$/, + alias('redux-toolkit'), ) - // console.log(old, '=>', r.request) + //console.log(old, '=>', r.request) }, ), ) + if (suffix === 'production.min.cjs') { ;(config.resolve ??= {}).mainFields = ['main', 'module'] } @@ -178,6 +185,6 @@ module.exports = entryPoints ].map((e) => ({ ...e, name: e.name + ` (.modern.mjs)`, - modifyWebpackConfig: withRtkPath('.modern.mjs'), + modifyWebpackConfig: withRtkPath('modern.mjs'), })), )