Skip to content

fix(shims): import.meta.url not being removed by tree-shaking#1463

Merged
Timeless0911 merged 4 commits intoweb-infra-dev:mainfrom
sylingd:fix/shim-require
Jan 30, 2026
Merged

fix(shims): import.meta.url not being removed by tree-shaking#1463
Timeless0911 merged 4 commits intoweb-infra-dev:mainfrom
sylingd:fix/shim-require

Conversation

@sylingd
Copy link
Copy Markdown
Contributor

@sylingd sylingd commented Jan 30, 2026

Summary

当前版本,在开启 shims.esm.require 后,即使未实际使用require,也会在产物中残留/*#__PURE__*/ import.meta.url;的代码。

image

该代码会被 rspack 认为存在 side effect,导致 tree shaking 失效

image

修改后,此残留代码被移除。已验证不影响存在 require 的场景(含直接运行 rslib 产物、使用 rspack 在项目中二次打包 rslib 的产物)

In the current version, even if require is not actually used, the code /*#__PURE__*/ import.meta.url; will still remain in the code after enabling shims.esm.require. This code is considered by rspack to have a side effect, causing tree shaking to fail. After modification, this residual code has been removed.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@Timeless0911 Timeless0911 changed the title fix(cli): import.meta.url not be being tree-shaking fix(shims): import.meta.url not being removed by tree-shaking Jan 30, 2026
@Timeless0911
Copy link
Copy Markdown
Contributor

Thanks, can you update the test snapshots?

Timeless0911
Timeless0911 previously approved these changes Jan 30, 2026
@Timeless0911 Timeless0911 enabled auto-merge (squash) January 30, 2026 10:01
@Timeless0911 Timeless0911 merged commit 72bc873 into web-infra-dev:main Jan 30, 2026
11 checks passed
@sylingd sylingd deleted the fix/shim-require branch January 30, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants