Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

设置react alias时兼容pnpm workspace #14194

Merged
merged 8 commits into from
Jul 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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