Skip to content

Commit

Permalink
feat(builder): include tslib in lib-polyfill.js (#4712)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Sep 22, 2023
1 parent 4e3310b commit 5b4bf21
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 10 deletions.
9 changes: 9 additions & 0 deletions .changeset/violet-carrots-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@modern-js/builder-webpack-provider': patch
'@modern-js/builder-rspack-provider': patch
'@modern-js/builder': patch
---

feat(builder): include tslib in lib-polyfill.js

feat(builder): 拆分 tslib 到 lib-polyfill.js 中
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
"name": "lib-polyfill",
"priority": 0,
"reuseExistingChunk": true,
"test": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(core-js\\|@babel\\\\/runtime\\|@swc\\\\/helpers\\)\\[\\\\\\\\/\\]/,
"test": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(tslib\\|core-js\\|@babel\\\\/runtime\\|@swc\\\\/helpers\\)\\[\\\\\\\\/\\]/,
},
"lib-react": {
"name": "lib-react",
Expand Down Expand Up @@ -1397,7 +1397,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
"name": "lib-polyfill",
"priority": 0,
"reuseExistingChunk": true,
"test": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(core-js\\|@babel\\\\/runtime\\|@swc\\\\/helpers\\)\\[\\\\\\\\/\\]/,
"test": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(tslib\\|core-js\\|@babel\\\\/runtime\\|@swc\\\\/helpers\\)\\[\\\\\\\\/\\]/,
},
"lib-react": {
"name": "lib-react",
Expand Down Expand Up @@ -2598,7 +2598,7 @@ exports[`tools.rspack > should match snapshot 1`] = `
"name": "lib-polyfill",
"priority": 0,
"reuseExistingChunk": true,
"test": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(core-js\\|@babel\\\\/runtime\\|@swc\\\\/helpers\\)\\[\\\\\\\\/\\]/,
"test": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(tslib\\|core-js\\|@babel\\\\/runtime\\|@swc\\\\/helpers\\)\\[\\\\\\\\/\\]/,
},
"lib-react": {
"name": "lib-react",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
"name": "lib-polyfill",
"priority": 0,
"reuseExistingChunk": true,
"test": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(core-js\\|@babel\\\\/runtime\\|@swc\\\\/helpers\\)\\[\\\\\\\\/\\]/,
"test": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(tslib\\|core-js\\|@babel\\\\/runtime\\|@swc\\\\/helpers\\)\\[\\\\\\\\/\\]/,
},
"lib-react": {
"name": "lib-react",
Expand Down Expand Up @@ -1700,7 +1700,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ
"name": "lib-polyfill",
"priority": 0,
"reuseExistingChunk": true,
"test": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(core-js\\|@babel\\\\/runtime\\|@swc\\\\/helpers\\)\\[\\\\\\\\/\\]/,
"test": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(tslib\\|core-js\\|@babel\\\\/runtime\\|@swc\\\\/helpers\\)\\[\\\\\\\\/\\]/,
},
"lib-react": {
"name": "lib-react",
Expand Down
1 change: 1 addition & 0 deletions packages/builder/builder/src/plugins/splitChunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ async function splitByExperience(
}
if (polyfill === 'entry' || polyfill === 'usage') {
packageRegExps.polyfill = createDependenciesRegExp(
'tslib',
'core-js',
'@babel/runtime',
'@swc/helpers',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ exports[`plugins/splitChunks > 'should set split-by-experience config' 1`] = `
"name": "lib-polyfill",
"priority": 0,
"reuseExistingChunk": true,
"test": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(core-js\\|@babel\\\\/runtime\\|@swc\\\\/helpers\\)\\[\\\\\\\\/\\]/,
"test": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(tslib\\|core-js\\|@babel\\\\/runtime\\|@swc\\\\/helpers\\)\\[\\\\\\\\/\\]/,
},
"lib-react": {
"name": "lib-react",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Builder supports the following chunk splitting strategies:

Builder adopts the `split-by-experience` strategy by default, which is a strategy we have developed from experience. Specifically, when the following npm packages are referenced in your project, they will automatically be split into separate chunks:

- `lib-polyfill.js`: includes `core-js`, `@babel/runtime`, `@swc/helpers`.
- `lib-polyfill.js`: includes `core-js`, `@babel/runtime`, `@swc/helpers`, `tslib`.
- `lib-react.js`: includes `react`, `react-dom`.
- `lib-router.js`: includes `react-router`, `react-router-dom`, `history`, `@remix-run/router`.
- `lib-lodash.js`: includes `lodash`, `lodash-es`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Builder supports the following chunk splitting strategies:

Builder adopts the `split-by-experience` strategy by default, which is a strategy we have developed from experience. Specifically, when the following npm packages are referenced in your project, they will automatically be split into separate chunks:

- `lib-polyfill.js`: includes `core-js`, `@babel/runtime`, `@swc/helpers`.
- `lib-polyfill.js`: includes `core-js`, `@babel/runtime`, `@swc/helpers`, `tslib`.
- `lib-react.js`: includes `react`, `react-dom`.
- `lib-router.js`: includes `react-router`, `react-router-dom`, `history`, `@remix-run/router`.
- `lib-lodash.js`: includes `lodash`, `lodash-es`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Builder 支持设置以下几种拆包策略:

Builder 默认采用 `split-by-experience` 策略,这是我们根据经验制定的策略。具体来说,当你的项目中引用了以下 npm 包时,它们会自动被拆分为单独的 chunk:

- `lib-polyfill.js`:包含 `core-js``@babel/runtime``@swc/helpers`
- `lib-polyfill.js`:包含 `core-js``@babel/runtime``@swc/helpers``tslib`
- `lib-react.js`:包含 `react``react-dom`
- `lib-router.js`:包含 `react-router``react-router-dom``history``@remix-run/router`
- `lib-lodash.js`:包含 `lodash``lodash-es`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Builder 支持设置以下几种拆包策略:

Builder 默认采用 `split-by-experience` 策略,这是我们根据经验制定的策略。具体来说,当你的项目中引用了以下 npm 包时,它们会自动被拆分为单独的 chunk:

- `lib-polyfill.js`:包含 `core-js``@babel/runtime``@swc/helpers`
- `lib-polyfill.js`:包含 `core-js``@babel/runtime``@swc/helpers``tslib`
- `lib-react.js`:包含 `react``react-dom`
- `lib-router.js`:包含 `react-router``react-router-dom``history``@remix-run/router`
- `lib-lodash.js`:包含 `lodash``lodash-es`
Expand Down

0 comments on commit 5b4bf21

Please sign in to comment.