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

Fix/browserslist #10389

Merged
merged 1 commit into from
Mar 14, 2023
Merged

Fix/browserslist #10389

merged 1 commit into from
Mar 14, 2023

Conversation

wyy0512
Copy link
Contributor

@wyy0512 wyy0512 commented Feb 3, 2023

修复 browserslist 预打包产物中 require.resolve 报错
close #10356


function fixBrowserslist(target) {
const content = fs.readFileSync(target, 'utf-8');
const match = content.match(/require\(__(webpack|nccwpck)_require__\((\S*)\).resolve/);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const match = content.match(/require\(__(webpack|nccwpck)_require__\((\S*)\).resolve/);
const match = content.match(/require\(__(webpack|nccwpck)_require__\((\d+)\).resolve/);


function fixBrowserslist(target) {
const content = fs.readFileSync(target, 'utf-8');
const match = content.match(/require\(__(webpack|nccwpck)_require__\((\S*)\).resolve/);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么会存在 nccwpck 和 webpack 两种变量名,是不同 ncc 版本引起的?

packages/deps/scripts/fixBrowserslist.js Show resolved Hide resolved
@fz6m
Copy link
Contributor

fz6m commented Feb 3, 2023

更好的解法是找到 browserslist 这个包的位置(以 babel 为 base 起点解析),直接把源码里 require.resolve 复写成 eval("require").resolve ,之后再预打包。

@vagusX
Copy link

vagusX commented Feb 3, 2023

更好的解法是找到 browserslist 这个包的位置(以 babel 为 base 起点解析),直接把源码里 require.resolve 复写成 eval("require").resolve ,之后再预打包。

应该把所有的 require.resolve 复写掉

@fz6m
Copy link
Contributor

fz6m commented Feb 3, 2023

我在 #10396 提了一个 umi 4 可靠的解法,比较复杂。

由于 umi 4 不能使用 browserslist ,所以会报错也是合理的,对 umi 4 修复该问题,我持中立态度。

关于 umi 3 了解的不多,如果没有配置 browserslist 的设计,不建议修复该问题。

@sorrycc
Copy link
Member

sorrycc commented Feb 6, 2023

我在 #10396 提了一个 umi 4 可靠的解法,比较复杂。

由于 umi 4 不能使用 browserslist ,所以会报错也是合理的,对 umi 4 修复该问题,我持中立态度。

关于 umi 3 了解的不多,如果没有配置 browserslist 的设计,不建议修复该问题。

Umi 3 有 browserslist 的配置的。

@vagusX
Copy link

vagusX commented Feb 23, 2023

umi 3 还处理嘛

@vercel
Copy link

vercel bot commented Mar 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
umi ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 13, 2023 at 8:25AM (UTC)

Copy link
Member

@PeachScript PeachScript left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@PeachScript PeachScript merged commit fc5f76d into umijs:3.x Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants