chore: use Rslib to bundle @rspack/core#9899
Conversation
✅ Deploy Preview for rspack canceled.
|
e8f14ad to
ef30b0f
Compare
CodSpeed Performance ReportMerging #9899 will not alter performanceComparing Summary
|
0afc46d to
e1809b7
Compare
@rspack/core
8e3082a to
5caf36c
Compare
packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/2.snap.txt
Show resolved
Hide resolved
5caf36c to
2d0a495
Compare
|
I think the bloated bundled size is due to Rspack doesn't allow concatenated module for CJS output? |
chenjiahan
left a comment
There was a problem hiding this comment.
LGTM👍
After checking the snapshots, I found that the __nested_webpack_require_18_37__ variable is quite ugly.
Maybe we should use scripts/prepare-container-runtime.js (or some other methods) to transform src/runtime/cssExtractHmr.ts to improve the generated code.
We can use the same minify config as Rsbuild to output a smaller bundle size. https://github.com/web-infra-dev/rsbuild/blob/6c2a605b7cfc2c07a8d1f47ed706d6abe6ab12c3/scripts/config/rslib.config.ts#L9-L20 |
|
Let's merge this PR first and further optimize the bundle size and output code readability in subsequent PRs. |
@fi3ework In fact, if we set |
|
The output of @chenjiahan The snapshots seems to show the result of This renaming behavior found some edge cases, but it should be in line with expectations in this test case and needs to be confirmed again. @JSerFeng cc |
|
I'm not saying Rslib is built incorrectly, just that it's not easy to read. In an Rspack application, |
We can transform via SWC Compiler API provided by Rspack in the near future. |

Summary
This PR use Rslib to bundle
@rspack/core.Bundle size:
dist/cssExtractHmr.js: 5.70 KB = 5.57 kBdist/cssExtractLoader.js: 10.27 KB = 10.03 kBdist/worker.js: 66.83 KB = 65.26 kBdist/index.js: 695.87 KB = 712.57 kBdist/cssExtractHmr.js: 6.2 kBdist/cssExtractLoader.js: 10.6 kBdist/worker.js: 71.5 kBdist/index.js: 772.0 kBBelow are some things that need to be explained and documented:
tscsince Rslib use Typescript Compiler API to genenrate declaration files.tsc-aliassince Rslib internally support redirect alias in declaration files via@ast-grep/napi.tsconfig.api.extractor.jsonfile to overridepathsintsconfig.jsonsince api-extractor will throw errors if correct paths which in prebundle foldercompiledare applied.CachedInputFileSystem.d.tsfile to prevent ts error when prebundle.index.d.tsforResolveRequesttype export since it is not used now.import z from "zod";instead ofimport { z } from "zod";module.exports = rspack;in source code and add a footerjs: "module.exports = __webpack_exports__.default;"instead to make default export in cjs work.module.exports = __webpack_exports__.default;when bundleworker.jsto make default export in cjs work.@ts-expect-errorsince we use correctpathsintsconfig.jsonnow.{ __webpack_require__ }to{ __webpack_require__: __webpack_require__ }to avoid parser bug. can be reset when fix: should rename __webpack_require__ pat in parameters #10036 is released in Rslib.Checklist