Skip to content

chore: migrate CommonJS rspack configs to ESM#423

Merged
chenjiahan merged 6 commits intomainfrom
chenjiahan/chore-rspack-config-esm
Apr 12, 2026
Merged

chore: migrate CommonJS rspack configs to ESM#423
chenjiahan merged 6 commits intomainfrom
chenjiahan/chore-rspack-config-esm

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

Summary

  • migrate CommonJS rspack.config.* files to ESM rspack.config.mjs across the repo
  • replace require and legacy __dirname helpers with import and import.meta.dirname, and standardize exports on export default defineConfig(...)
  • update example config references that pointed to renamed config files

Related Links

  • None

Verification

  • node --check for all rspack.config.{js,mjs} files
  • pnpm run build in rspack/react
  • pnpm run build:client && pnpm run build:server in rspack/react-ssr-esm
  • pnpm run build in rspack/nest-alias still fails due to existing @components/* resolution errors in common-libs/dist
  • pnpm exec rspack build -c rspack.config.loader.mjs in rspack/eslint still fails because eslint-loader is not resolvable in the example

Copilot AI review requested due to automatic review settings April 12, 2026 01:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates numerous Rspack example configurations from CommonJS to ESM across the repo, standardizing on export default defineConfig(...) and replacing legacy __dirname/require patterns with ESM-friendly equivalents (notably import.meta.dirname and import.meta.resolve).

Changes:

  • Convert many rspack.config.js files to rspack.config.mjs using ESM import + export default defineConfig(...).
  • Replace __dirname usage with import.meta.dirname and require.resolve(...) with import.meta.resolve(...) where needed.
  • Update example script/config references (e.g., rspack/eslint loader config script) to point at renamed .mjs configs.

Reviewed changes

Copilot reviewed 91 out of 91 changed files in this pull request and generated no comments.

Show a summary per file
File Description
rspack/worklet/rspack.config.mjs Convert config to ESM + defineConfig, switch to import.meta.dirname.
rspack/worker/rspack.config.mjs Add ESM config replacement for removed CJS config.
rspack/worker/rspack.config.js Remove legacy CommonJS config.
rspack/workbox-webpack-plugin/rspack.config.mjs Convert to ESM imports/exports and defineConfig.
rspack/webpack-stats-plugin/rspack.config.mjs Add ESM config replacement for removed CJS config.
rspack/webpack-stats-plugin/rspack.config.js Remove legacy CommonJS config.
rspack/webpack-bundle-analyzer/rspack.config.mjs Add ESM config replacement for removed CJS config.
rspack/webpack-bundle-analyzer/rspack.config.js Remove legacy CommonJS config.
rspack/wasm-simple/rspack.config.mjs Convert to ESM + defineConfig.
rspack/vue/rspack.config.mjs Convert to ESM + defineConfig, switch to import.meta.dirname.
rspack/vue-vanilla/rspack.config.mjs Convert to ESM + defineConfig, switch to import.meta.dirname.
rspack/vue-tsx/rspack.config.mjs Convert to ESM + defineConfig, switch to import.meta.dirname.
rspack/vue-jsx/rspack.config.mjs Convert to ESM + defineConfig, switch to import.meta.dirname.
rspack/vanilla-extract-css/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/type-reexports-presence/rspack.config.mjs Wrap existing default export with defineConfig.
rspack/ts-checker-rspack-plugin/rspack.config.mjs Convert to ESM + defineConfig.
rspack/treeshaking-transform-imports/rspack.config.mjs Convert to ESM + defineConfig, switch to import.meta.dirname.
rspack/terser-webpack-plugin/rspack.config.mjs Add ESM config replacement for removed CJS config.
rspack/terser-webpack-plugin/rspack.config.js Remove legacy CommonJS config.
rspack/svgr/rspack.config.mjs Convert to ESM + defineConfig.
rspack/svelte/rspack.config.js Remove createRequire usage and move fully to ESM-friendly patterns.
rspack/styled-components/rspack.config.mjs Convert to ESM + defineConfig.
rspack/stats/rspack.config.mjs Convert to ESM + defineConfig, switch to import.meta.dirname.
rspack/source-map-with-vscode-debugging/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/solid/rspack.config.mjs Convert to ESM + defineConfig, switch to import.meta.dirname.
rspack/sentry/rspack.config.mjs Convert to ESM + defineConfig.
rspack/rspack-manifest-plugin/rspack.config.mjs Convert to ESM + defineConfig.
rspack/react/rspack.config.mjs Convert to ESM + defineConfig.
rspack/react-with-sass/rspack.config.mjs Convert to ESM + defineConfig.
rspack/react-with-less/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/react-with-extract-css/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/react-ssr-esm/rspack.config.server.js Use defineConfig and replace manual __dirname derivation with import.meta.dirname.
rspack/react-ssr-esm/rspack.config.client.js Use defineConfig and replace manual __dirname derivation with import.meta.dirname.
rspack/react-refresh/rspack.config.mjs Convert to ESM + defineConfig.
rspack/react-refresh-esm/rspack.config.mjs Convert to ESM + defineConfig.
rspack/react-refresh-babel-loader/rspack.config.mjs Convert to ESM + defineConfig, replace require.resolve with import.meta.resolve + fileURLToPath.
rspack/react-compiler-babel/rspack.config.mjs Convert to ESM + defineConfig.
rspack/react-compiler-babel-ts/rspack.config.mjs Convert to ESM + defineConfig.
rspack/proxy/rspack.config.mjs Convert config function export to export default defineConfig((env, argv) => ...), switch to import.meta.dirname.
rspack/preact/rspack.config.mjs Convert to ESM + defineConfig.
rspack/preact-refresh/rspack.config.mjs Convert to ESM + defineConfig.
rspack/postcss-loader/rspack.config.mjs Convert to ESM + defineConfig, switch to import.meta.dirname.
rspack/polyfill/rspack.config.mjs Convert to ESM + defineConfig, replace require.resolve with import.meta.resolve + fileURLToPath.
rspack/perfsee/rspack.config.mjs Convert to ESM + defineConfig, switch to import.meta.dirname.
rspack/node-polyfill/rspack.config.mjs Add ESM config replacement for removed CJS config + import.meta.dirname.
rspack/node-polyfill/rspack.config.js Remove legacy CommonJS config.
rspack/node-globals-shim/rspack.config.mjs Add ESM config replacement for removed CJS config + import.meta.dirname.
rspack/node-globals-shim/rspack.config.js Remove legacy CommonJS config.
rspack/nestjs/rspack.config.mjs Convert to ESM + defineConfig, switch to import.meta.dirname, update resolve-check to import.meta.resolve.
rspack/nest-alias/rspack.config.mjs Add ESM config replacement for removed CJS config + import.meta.dirname.
rspack/nest-alias/rspack.config.js Remove legacy CommonJS config.
rspack/multi-entry/rspack.config.mjs Convert to ESM + defineConfig.
rspack/monaco-editor-webpack-plugin/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/monaco-editor-ts-react/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/monaco-editor-js/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/module-federation-v1/lib2/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/module-federation-v1/lib1/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/module-federation-v1/app/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/module-federation-v1.5/lib2/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/module-federation-v1.5/lib1/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/module-federation-v1.5/app/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/minify-test/rspack.config.mjs Convert to ESM + defineConfig, switch to ESM import for rspack.
rspack/loader-compat/rspack.config.mjs Convert to ESM + defineConfig.
rspack/lightingcss-loader/rspack.config.mjs Convert to ESM + defineConfig.
rspack/license-webpack-plugin/rspack.config.mjs Convert to ESM + defineConfig.
rspack/library-umd/rspack.config.mjs Normalize ESM config formatting and quoting; add @ts-check.
rspack/library-esm/rspack.config.mjs Add @ts-check header.
rspack/library-cjs/rspack.config.mjs Normalize ESM config formatting/quoting; add @ts-check.
rspack/inline-enum/rspack.config.mjs Wrap existing default export with defineConfig.
rspack/inline-const/rspack.config.mjs Wrap existing default export with defineConfig.
rspack/inline-const-enum/rspack.config.mjs Wrap existing default export with defineConfig.
rspack/html-webpack-plugin/rspack.config.mjs Add ESM config replacement for removed CJS config.
rspack/html-webpack-plugin/rspack.config.js Remove legacy CommonJS config.
rspack/hooks-after-resolve/rspack.config.mjs Convert to ESM + defineConfig.
rspack/generate-package-json-webpack-plugin/rspack.config.mjs Convert to ESM + defineConfig.
rspack/extract-license/rspack.config.mjs Convert to ESM + defineConfig, switch to import.meta.dirname.
rspack/express/rspack.config.mjs Convert to ESM + defineConfig, switch to import.meta.dirname.
rspack/eslint/rspack.config.mjs Add ESM config replacement for removed CJS config + import.meta.dirname.
rspack/eslint/rspack.config.loader.mjs Convert loader config to ESM + defineConfig, switch to import.meta.dirname.
rspack/eslint/rspack.config.js Remove legacy CommonJS config.
rspack/eslint/package.json Update dev:loader script to reference .mjs config.
rspack/emotion/rspack.config.mjs Convert to ESM + defineConfig.
rspack/dll/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/dll-reference/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/css-parser-generator-options/rspack.config.mjs Convert to ESM + defineConfig, replace __dirname paths.
rspack/css-chunking-plugin/rspack.config.mjs Convert to ESM + defineConfig.
rspack/cra/rspack.config.mjs Convert to ESM + defineConfig.
rspack/cra-ts/rspack.config.mjs Convert to ESM + defineConfig.
rspack/builtin-swc-loader/rspack.config.mjs Remove legacy createRequire/manual __dirname, switch to import.meta.dirname and import.meta.resolve + fileURLToPath.
rspack/basic-ts/rspack.config.mjs Remove manual __dirname derivation in favor of import.meta.dirname.
rsdoctor/rspack/rspack.config.mjs Convert to ESM + defineConfig.
Comments suppressed due to low confidence (1)

rspack/nestjs/rspack.config.mjs:105

  • In this externals callback, callback can be invoked twice when import.meta.resolve(resource) throws: once inside the catch (callback(null, resource)) and then again unconditionally afterward (callback()). Ensure the callback is called exactly once (e.g., return callback(null, resource) in the catch, or an else with a return callback()).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chenjiahan chenjiahan merged commit f44804b into main Apr 12, 2026
4 checks passed
@chenjiahan chenjiahan deleted the chenjiahan/chore-rspack-config-esm branch April 12, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants