chore: migrate CommonJS rspack configs to ESM#423
Merged
chenjiahan merged 6 commits intomainfrom Apr 12, 2026
Merged
Conversation
There was a problem hiding this comment.
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.jsfiles torspack.config.mjsusing ESMimport+export default defineConfig(...). - Replace
__dirnameusage withimport.meta.dirnameandrequire.resolve(...)withimport.meta.resolve(...)where needed. - Update example script/config references (e.g.,
rspack/eslintloader config script) to point at renamed.mjsconfigs.
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
externalscallback,callbackcan be invoked twice whenimport.meta.resolve(resource)throws: once inside thecatch(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 anelsewith areturn callback()).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rspack.config.*files to ESMrspack.config.mjsacross the reporequireand legacy__dirnamehelpers withimportandimport.meta.dirname, and standardize exports onexport default defineConfig(...)Related Links
Verification
node --checkfor allrspack.config.{js,mjs}filespnpm run buildinrspack/reactpnpm run build:client && pnpm run build:serverinrspack/react-ssr-esmpnpm run buildinrspack/nest-aliasstill fails due to existing@components/*resolution errors incommon-libs/distpnpm exec rspack build -c rspack.config.loader.mjsinrspack/eslintstill fails becauseeslint-loaderis not resolvable in the example