Skip to content

Commit

Permalink
设置react alias时兼容pnpm workspace (NervJS#14194)
Browse files Browse the repository at this point in the history
* 设置react alias时兼容pnpm workspace

---------

Co-authored-by: Flame <wshx1938@163.com>
Co-authored-by: 大喵 <running@vip.163.com>
  • Loading branch information
3 people authored and yechunxi committed Aug 4, 2023
1 parent 438be99 commit fd78231
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/taro-plugin-react/src/webpack.mini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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。
Expand Down

0 comments on commit fd78231

Please sign in to comment.