Skip to content

refactor(plugin-svgr): use import.meta.dirname for loaders#7483

Merged
chenjiahan merged 1 commit intomainfrom
chenjiahan/refactor-plugin-svgr-loader-paths
Apr 12, 2026
Merged

refactor(plugin-svgr): use import.meta.dirname for loaders#7483
chenjiahan merged 1 commit intomainfrom
chenjiahan/refactor-plugin-svgr-loader-paths

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

Summary

This PR updates @rsbuild/plugin-svgr to resolve loader.mjs and assetLoader.mjs with import.meta.dirname. It removes the extra fileURLToPath-based __dirname shim while keeping the resolved loader paths unchanged.

Related Links

None

Copilot AI review requested due to automatic review settings April 11, 2026 12:25
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread packages/plugin-svgr/src/index.ts
Copy link
Copy Markdown
Contributor

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 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 / __dirname shim used for resolving loader file paths.
  • Updated SVGR-related .loader(...) configuration to use path.join(import.meta.dirname, ...) for loader.mjs and assetLoader.mjs.

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

@chenjiahan chenjiahan merged commit c6d430f into main Apr 12, 2026
10 checks passed
@chenjiahan chenjiahan deleted the chenjiahan/refactor-plugin-svgr-loader-paths branch April 12, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants