refactor(plugin-svgr): use import.meta.dirname for loaders#7483
refactor(plugin-svgr): use import.meta.dirname for loaders#7483chenjiahan merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the SVGR plugin by removing the manual __dirname shim and replacing it with the native import.meta.dirname for resolving loader paths. A critical issue was identified regarding Node.js compatibility: import.meta.dirname is not available in Node.js 18, which is still supported by Rsbuild, and its use will cause runtime errors when passed to path.join.
There was a problem hiding this comment.
Pull request overview
This PR refactors @rsbuild/plugin-svgr loader path resolution to rely on import.meta.dirname instead of a fileURLToPath(import.meta.url)-based __dirname shim, keeping the resulting loader paths the same while simplifying the implementation.
Changes:
- Removed the
fileURLToPath/__dirnameshim used for resolving loader file paths. - Updated SVGR-related
.loader(...)configuration to usepath.join(import.meta.dirname, ...)forloader.mjsandassetLoader.mjs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
This PR updates
@rsbuild/plugin-svgrto resolveloader.mjsandassetLoader.mjswithimport.meta.dirname. It removes the extrafileURLToPath-based__dirnameshim while keeping the resolved loader paths unchanged.Related Links
None