diff --git a/e2e/cases/performance/moment-locale/index.test.ts b/e2e/cases/performance/moment-locale/index.test.ts deleted file mode 100644 index 33006d06d1..0000000000 --- a/e2e/cases/performance/moment-locale/index.test.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { expect, getFileContent, test } from '@e2e/helper'; - -// TODO: Fix this test -test.skip('should retain Moment locales when removeMomentLocale is false (default)', async ({ - build, -}) => { - const rsbuild = await build({ - config: { - output: { - sourceMap: { - js: 'source-map', - }, - }, - performance: { - chunkSplit: { - strategy: 'custom', - splitChunks: { - cacheGroups: { - react: { - test: /moment/, - name: 'moment-js', - chunks: 'all', - }, - }, - }, - }, - }, - }, - runServer: false, - }); - - const files = rsbuild.getDistFiles({ sourceMaps: true }); - - const momentMapFile = getFileContent(files, 'moment-js.js.map'); - - expect(momentMapFile.includes('moment/locale')).toBeTruthy(); -}); - -test('should remove Moment locales when removeMomentLocale is true', async ({ - build, -}) => { - const rsbuild = await build({ - config: { - output: { - sourceMap: { - js: 'source-map', - }, - }, - performance: { - removeMomentLocale: true, - chunkSplit: { - strategy: 'custom', - splitChunks: { - cacheGroups: { - react: { - test: /moment/, - name: 'moment-js', - chunks: 'all', - }, - }, - }, - }, - }, - }, - runServer: false, - }); - - const files = rsbuild.getDistFiles({ sourceMaps: true }); - - const momentMapFile = getFileContent(files, 'moment-js.js.map'); - - expect(momentMapFile.includes('moment/locale')).toBeFalsy(); -}); diff --git a/e2e/cases/performance/moment-locale/src/index.js b/e2e/cases/performance/moment-locale/src/index.js deleted file mode 100644 index 96e16fa9c4..0000000000 --- a/e2e/cases/performance/moment-locale/src/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import moment from 'moment'; - -moment([2007, 0, 28]).format('dddd, MMMM Do YYYY'); diff --git a/e2e/package.json b/e2e/package.json index 058e82fa49..57d644d8b9 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -12,7 +12,6 @@ "@module-federation/runtime-tools": "0.22.1", "core-js": "^3.47.0", "lodash": "^4.17.21", - "moment": "^2.30.1", "preact": "^10.28.2", "react": "^19.2.3", "react-dom": "^19.2.3", diff --git a/packages/core/src/createRsbuild.ts b/packages/core/src/createRsbuild.ts index de40d99074..a87a63df12 100644 --- a/packages/core/src/createRsbuild.ts +++ b/packages/core/src/createRsbuild.ts @@ -38,7 +38,6 @@ import { pluginLazyCompilation } from './plugins/lazyCompilation'; import { pluginManifest } from './plugins/manifest'; import { pluginMinimize } from './plugins/minimize'; import { pluginModuleFederation } from './plugins/moduleFederation'; -import { pluginMoment } from './plugins/moment'; import { pluginNodeAddons } from './plugins/nodeAddons'; import { pluginNonce } from './plugins/nonce'; import { pluginOutput } from './plugins/output'; @@ -95,7 +94,6 @@ function applyDefaultPlugins( pluginHtml(context), pluginAppIcon(), pluginWasm(), - pluginMoment(), pluginNodeAddons(), pluginDefine(), pluginCss(), diff --git a/packages/core/src/defaultConfig.ts b/packages/core/src/defaultConfig.ts index 9241fe0dd5..f839308af3 100644 --- a/packages/core/src/defaultConfig.ts +++ b/packages/core/src/defaultConfig.ts @@ -146,7 +146,6 @@ const getDefaultToolsConfig = (): NormalizedToolsConfig => ({ const getDefaultPerformanceConfig = (): NormalizedPerformanceConfig => ({ printFileSize: true, removeConsole: false, - removeMomentLocale: false, chunkSplit: { strategy: 'split-by-experience', }, diff --git a/packages/core/src/plugins/moment.ts b/packages/core/src/plugins/moment.ts deleted file mode 100644 index 91439fb466..0000000000 --- a/packages/core/src/plugins/moment.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type { RsbuildPlugin } from '../types'; - -export const pluginMoment = (): RsbuildPlugin => ({ - name: 'rsbuild:moment', - - setup(api) { - api.modifyBundlerChain((chain, { environment, bundler }) => { - const { config } = environment; - - if (config.performance.removeMomentLocale) { - // Moment.js includes a lots of locale data by default. - // We can using IgnorePlugin to allow the user to opt into importing specific locales. - // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack - chain.plugin('remove-moment-locale').use(bundler.IgnorePlugin, [ - { - resourceRegExp: /^\.\/locale$/, - contextRegExp: /moment$/, - }, - ]); - } - }); - }, -}); diff --git a/packages/core/src/types/config.ts b/packages/core/src/types/config.ts index 540d19aeb0..5448b716a8 100644 --- a/packages/core/src/types/config.ts +++ b/packages/core/src/types/config.ts @@ -735,12 +735,6 @@ export interface PerformanceConfig { */ removeConsole?: boolean | ConsoleType[]; - /** - * Whether to remove the locales of [moment.js](https://momentjs.com/). - * @default false - */ - removeMomentLocale?: boolean; - /** * To enable or configure persistent build cache. * @experimental This feature is experimental and may be changed in the future. diff --git a/packages/core/tests/__snapshots__/environments.test.ts.snap b/packages/core/tests/__snapshots__/environments.test.ts.snap index dd57911e70..e294079b19 100644 --- a/packages/core/tests/__snapshots__/environments.test.ts.snap +++ b/packages/core/tests/__snapshots__/environments.test.ts.snap @@ -92,7 +92,6 @@ exports[`environment config > should normalize environment config correctly 1`] }, "printFileSize": true, "removeConsole": false, - "removeMomentLocale": false, }, "resolve": { "alias": { @@ -250,7 +249,6 @@ exports[`environment config > should normalize environment config correctly 2`] }, "printFileSize": true, "removeConsole": false, - "removeMomentLocale": false, }, "resolve": { "alias": { @@ -412,7 +410,6 @@ exports[`environment config > should print environment config when inspect confi }, "printFileSize": true, "removeConsole": false, - "removeMomentLocale": false, }, "resolve": { "alias": { @@ -570,7 +567,6 @@ exports[`environment config > should print environment config when inspect confi }, "printFileSize": true, "removeConsole": false, - "removeMomentLocale": false, }, "resolve": { "alias": { @@ -748,7 +744,6 @@ exports[`environment config > should support modify environment config by api.mo }, "printFileSize": true, "removeConsole": false, - "removeMomentLocale": false, }, "resolve": { "alias": { @@ -906,7 +901,6 @@ exports[`environment config > should support modify environment config by api.mo }, "printFileSize": true, "removeConsole": false, - "removeMomentLocale": false, }, "resolve": { "alias": { @@ -1065,7 +1059,6 @@ exports[`environment config > should support modify environment config by api.mo }, "printFileSize": true, "removeConsole": false, - "removeMomentLocale": false, }, "resolve": { "alias": { @@ -1227,7 +1220,6 @@ exports[`environment config > should support modify single environment config by }, "printFileSize": true, "removeConsole": false, - "removeMomentLocale": false, }, "resolve": { "alias": { @@ -1385,7 +1377,6 @@ exports[`environment config > should support modify single environment config by }, "printFileSize": true, "removeConsole": false, - "removeMomentLocale": false, }, "resolve": { "alias": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 30f6e51746..e7f4e4d8d1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -88,9 +88,6 @@ importers: lodash: specifier: ^4.17.21 version: 4.17.21 - moment: - specifier: ^2.30.1 - version: 2.30.1 preact: specifier: ^10.28.2 version: 10.28.2 @@ -4944,9 +4941,6 @@ packages: resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==} engines: {node: '>=16 || 14 >=14.17'} - moment@2.30.1: - resolution: {integrity: sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==} - motion-dom@12.24.11: resolution: {integrity: sha512-DlWOmsXMJrV8lzZyd+LKjG2CXULUs++bkq8GZ2Sr0R0RRhs30K2wtY+LKiTjhmJU3W61HK+rB0GLz6XmPvTA1A==} @@ -10743,8 +10737,6 @@ snapshots: minipass@7.1.2: {} - moment@2.30.1: {} - motion-dom@12.24.11: dependencies: motion-utils: 12.24.10 diff --git a/website/docs/en/config/performance/remove-moment-locale.mdx b/website/docs/en/config/performance/remove-moment-locale.mdx deleted file mode 100644 index 1bbc67e175..0000000000 --- a/website/docs/en/config/performance/remove-moment-locale.mdx +++ /dev/null @@ -1,27 +0,0 @@ -# performance.removeMomentLocale - -- **Type:** `boolean` -- **Default:** `false` - -Whether to remove the locales of [moment.js](https://momentjs.com/). - -`moment.js` contains a lot of locales by default, which will increase the bundle size. - -When `moment.js` is used in the project, it is recommended to enable this option to automatically exclude all locales: - -```ts title="rsbuild.config.ts" -export default { - performance: { - removeMomentLocale: true, - }, -}; -``` - -Once enabled, you can load a specific locale via: - -```js -import moment from 'moment'; -import 'moment/locale/zh-cn'; - -moment.locale('zh-cn'); -``` diff --git a/website/docs/en/guide/start/features.mdx b/website/docs/en/guide/start/features.mdx index e33dea05fd..2a5b1a85b9 100644 --- a/website/docs/en/guide/start/features.mdx +++ b/website/docs/en/guide/start/features.mdx @@ -100,7 +100,6 @@ Overview of the main features supported by Rsbuild. | Analyze build process | Optional feature, use Rsdoctor to analyze build process | | | Analyze bundle size | Optional feature, analyze bundle size through Rsdoctor | | | Remove console | Optional feature, remove `console.[methodName]` in code | | -| Optimize moment.js size | Optional feature, remove the redundant locale files of moment.js | | | Dedupe packages | Optional feature, remove duplicate npm packages | | | Component on-demand import | Optional feature, selectively import code and styles from component libraries | | | Image compression | Optional feature, compress used image resources | | diff --git a/website/docs/zh/config/performance/remove-moment-locale.mdx b/website/docs/zh/config/performance/remove-moment-locale.mdx deleted file mode 100644 index eea690b79d..0000000000 --- a/website/docs/zh/config/performance/remove-moment-locale.mdx +++ /dev/null @@ -1,27 +0,0 @@ -# performance.removeMomentLocale - -- **类型:** `boolean` -- **默认值:** `false` - -是否移除 [moment.js](https://momentjs.com/) 的语言包文件。 - -`moment.js` 默认包含了大量的语言包文件,会导致打包后的包体积增大。 - -当项目中使用了 `moment.js` 时,推荐开启此选项,自动排除所有的语言包文件: - -```ts title="rsbuild.config.ts" -export default { - performance: { - removeMomentLocale: true, - }, -}; -``` - -开启后,可以通过以下方式来加载语言包文件: - -```js -import moment from 'moment'; -import 'moment/locale/zh-cn'; - -moment.locale('zh-cn'); -``` diff --git a/website/docs/zh/guide/start/features.mdx b/website/docs/zh/guide/start/features.mdx index f735c78989..8a8b9bc91a 100644 --- a/website/docs/zh/guide/start/features.mdx +++ b/website/docs/zh/guide/start/features.mdx @@ -93,18 +93,17 @@ ## 性能和调试 -| 功能 | 描述 | 相关链接 | -| ------------------- | -------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | -| 代码拆分 | Rsbuild 中内置了多种拆包策略,自动将代码包拆分为体积适中的文件 | | -| 展示产物体积 | 在生产模式构建后,默认展示所有静态资源的体积信息 | | -| 分析构建流程 | 可选功能,使用 Rsdoctor 分析构建流程 | | -| 分析产物体积 | 可选功能,通过 Rsdoctor 分析产物体积 | | -| 移除 console | 可选功能,移除代码中的 `console.[methodName]` | | -| 优化 moment.js 体积 | 可选功能,移除 moment.js 多余的 locale 文件 | | -| 移除重复包 | 可选功能,移除重复引用的 npm 包 | | -| 组件库按需引入 | 可选功能,按需引入组件库的代码和样式 | | -| 图片压缩 | 可选功能,对引用的图片资源进行压缩处理 | | -| Preload | 可选功能,对资源进行预加载 | | -| Prefetch | 可选功能,对资源进行预获取 | | -| Preconnect | 可选功能,对资源进行预连接 | | -| DNS prefetch | 可选功能,对资源进行 DNS 预获取 | | +| 功能 | 描述 | 相关链接 | +| -------------- | -------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | +| 代码拆分 | Rsbuild 中内置了多种拆包策略,自动将代码包拆分为体积适中的文件 | | +| 展示产物体积 | 在生产模式构建后,默认展示所有静态资源的体积信息 | | +| 分析构建流程 | 可选功能,使用 Rsdoctor 分析构建流程 | | +| 分析产物体积 | 可选功能,通过 Rsdoctor 分析产物体积 | | +| 移除 console | 可选功能,移除代码中的 `console.[methodName]` | | +| 移除重复包 | 可选功能,移除重复引用的 npm 包 | | +| 组件库按需引入 | 可选功能,按需引入组件库的代码和样式 | | +| 图片压缩 | 可选功能,对引用的图片资源进行压缩处理 | | +| Preload | 可选功能,对资源进行预加载 | | +| Prefetch | 可选功能,对资源进行预获取 | | +| Preconnect | 可选功能,对资源进行预连接 | | +| DNS prefetch | 可选功能,对资源进行 DNS 预获取 | |