From 619ca7b70610403b59ccd1cb1421ddf8305f7319 Mon Sep 17 00:00:00 2001 From: smoothdvd Date: Tue, 25 Jul 2023 10:09:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AEreact=20alias=E6=97=B6?= =?UTF-8?q?=E5=85=BC=E5=AE=B9pnpm=20workspace=20(#14194)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 设置react alias时兼容pnpm workspace --------- Co-authored-by: Flame Co-authored-by: 大喵 --- packages/taro-plugin-react/src/webpack.mini.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/taro-plugin-react/src/webpack.mini.ts b/packages/taro-plugin-react/src/webpack.mini.ts index 6c844a93ac8f..3b3ae6f614b1 100644 --- a/packages/taro-plugin-react/src/webpack.mini.ts +++ b/packages/taro-plugin-react/src/webpack.mini.ts @@ -21,8 +21,9 @@ function setAlias (ctx: IPluginContext, framework: Frameworks, chain) { const isProd = webpackConfig.mode === 'production' if (!isProd && config.mini?.debugReact !== true) { // 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积 + // 兼容pnpm workspace alias.set('react-reconciler$', 'react-reconciler/cjs/react-reconciler.production.min.js') - alias.set('react$', 'react/cjs/react.production.min.js') + alias.set('react$', require.resolve('react', { paths: [process.cwd()] }).replace(/[^/]*$/, 'cjs/react.production.min.js')) alias.set('react/jsx-runtime$', 'react/cjs/react-jsx-runtime.production.min.js') // 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。