diff --git a/.changeset/violet-carrots-relate.md b/.changeset/violet-carrots-relate.md new file mode 100644 index 000000000000..bda4092fb095 --- /dev/null +++ b/.changeset/violet-carrots-relate.md @@ -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 中 diff --git a/packages/builder/builder-rspack-provider/tests/plugins/__snapshots__/default.test.ts.snap b/packages/builder/builder-rspack-provider/tests/plugins/__snapshots__/default.test.ts.snap index 276dae5372b4..f6f5dcece9fd 100644 --- a/packages/builder/builder-rspack-provider/tests/plugins/__snapshots__/default.test.ts.snap +++ b/packages/builder/builder-rspack-provider/tests/plugins/__snapshots__/default.test.ts.snap @@ -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", @@ -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", @@ -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", diff --git a/packages/builder/builder-webpack-provider/tests/plugins/__snapshots__/default.test.ts.snap b/packages/builder/builder-webpack-provider/tests/plugins/__snapshots__/default.test.ts.snap index e7d5a7c57173..3b9666f8f415 100644 --- a/packages/builder/builder-webpack-provider/tests/plugins/__snapshots__/default.test.ts.snap +++ b/packages/builder/builder-webpack-provider/tests/plugins/__snapshots__/default.test.ts.snap @@ -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", @@ -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", diff --git a/packages/builder/builder/src/plugins/splitChunks.ts b/packages/builder/builder/src/plugins/splitChunks.ts index 575f5fea3b21..3dfbb53b96b2 100644 --- a/packages/builder/builder/src/plugins/splitChunks.ts +++ b/packages/builder/builder/src/plugins/splitChunks.ts @@ -117,6 +117,7 @@ async function splitByExperience( } if (polyfill === 'entry' || polyfill === 'usage') { packageRegExps.polyfill = createDependenciesRegExp( + 'tslib', 'core-js', '@babel/runtime', '@swc/helpers', diff --git a/packages/builder/builder/tests/plugins/__snapshots__/splitChunks.test.ts.snap b/packages/builder/builder/tests/plugins/__snapshots__/splitChunks.test.ts.snap index ce8915bd0748..71d58f4e8138 100644 --- a/packages/builder/builder/tests/plugins/__snapshots__/splitChunks.test.ts.snap +++ b/packages/builder/builder/tests/plugins/__snapshots__/splitChunks.test.ts.snap @@ -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", diff --git a/packages/document/builder-doc/docs/en/config/performance/chunkSplit.md b/packages/document/builder-doc/docs/en/config/performance/chunkSplit.md index 97ea9bb133d1..627d0d6647ba 100644 --- a/packages/document/builder-doc/docs/en/config/performance/chunkSplit.md +++ b/packages/document/builder-doc/docs/en/config/performance/chunkSplit.md @@ -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`. diff --git a/packages/document/builder-doc/docs/en/guide/optimization/split-chunk.md b/packages/document/builder-doc/docs/en/guide/optimization/split-chunk.md index 34a505c5b98b..5c5fe84755ef 100644 --- a/packages/document/builder-doc/docs/en/guide/optimization/split-chunk.md +++ b/packages/document/builder-doc/docs/en/guide/optimization/split-chunk.md @@ -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`. diff --git a/packages/document/builder-doc/docs/zh/config/performance/chunkSplit.md b/packages/document/builder-doc/docs/zh/config/performance/chunkSplit.md index 778afe6926ad..c04dbbc81f05 100644 --- a/packages/document/builder-doc/docs/zh/config/performance/chunkSplit.md +++ b/packages/document/builder-doc/docs/zh/config/performance/chunkSplit.md @@ -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`。 diff --git a/packages/document/builder-doc/docs/zh/guide/optimization/split-chunk.md b/packages/document/builder-doc/docs/zh/guide/optimization/split-chunk.md index c66b54f1cf0e..c20069680600 100644 --- a/packages/document/builder-doc/docs/zh/guide/optimization/split-chunk.md +++ b/packages/document/builder-doc/docs/zh/guide/optimization/split-chunk.md @@ -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`。