Skip to content

refactor(plugin-svgr): use internal asset loader#7482

Merged
chenjiahan merged 1 commit intomainfrom
chenjiahan/refactor-plugin-svgr-asset-loader
Apr 11, 2026
Merged

refactor(plugin-svgr): use internal asset loader#7482
chenjiahan merged 1 commit intomainfrom
chenjiahan/refactor-plugin-svgr-asset-loader

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

Summary

This PR replaces the prebundled url-loader / file-loader path in @rsbuild/plugin-svgr with an internal SVG asset loader. It keeps the mixed import asset handling intact while removing the extra package patches and prebundle setup.

Related Links

None

Copilot AI review requested due to automatic review settings April 11, 2026 11:42
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 to stop relying on prebundled/patch-managed url-loader + file-loader for mixed SVG imports, and instead uses a new internal SVG asset loader to preserve the same “inline under limit, otherwise emit file” behavior with fewer external build-time hacks.

Changes:

  • Replace the url-loader-based mixed import handling with a new internal assetLoader (built as assetLoader.mjs).
  • Remove prebundle setup and the file-loader / url-loader patched dependency workflow.
  • Update snapshots and package metadata to reflect the new loader path and dependency set.

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pnpm-workspace.yaml Removes patched dependency entries for file-loader / url-loader.
pnpm-lock.yaml Drops file-loader, url-loader, and related transitive deps from the lockfile.
patches/url-loader@4.1.1.patch Deletes the patch since url-loader is no longer used.
patches/file-loader@6.2.0.patch Deletes the patch since file-loader is no longer used.
packages/plugin-svgr/tests/snapshots/index.test.ts.snap Updates snapshot to expect the new internal loader path.
packages/plugin-svgr/src/loader-utils.d.ts Adds local typing for loader-utils.interpolateName usage in the new loader.
packages/plugin-svgr/src/index.ts Switches mixed-import URL handling to assetLoader.mjs.
packages/plugin-svgr/src/assetLoader.ts Introduces the internal raw loader implementing inline-or-emit SVG asset behavior.
packages/plugin-svgr/rslib.config.ts Adds assetLoader as a build entry and outputs it as .mjs.
packages/plugin-svgr/prebundle.config.ts Removes prebundle configuration (no longer needed).
packages/plugin-svgr/package.json Removes file-loader, url-loader, and prebundle from devDependencies and scripts; keeps package files focused on dist.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

packages/plugin-svgr/src/index.ts:263

  • generatorOptions?.filename can be an AssetModuleFilename function (not just a string) and may also be undefined; passing it as the name option will break assetLoader (it relies on loader-utils.interpolateName, which expects a template string or a (resourcePath, resourceQuery) callback). Please ensure the option passed here is always a string template (e.g. fall back to Rsbuild’s default svg filename) and handle the function case explicitly (e.g. by deriving a string template or using a different code path).
            .use(CHAIN_ID.USE.URL)
            .loader(path.resolve(__dirname, './assetLoader.mjs'))
            .options({
              limit: maxSize,
              name: generatorOptions?.filename,
            });

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

Comment thread packages/plugin-svgr/src/assetLoader.ts
Comment thread packages/plugin-svgr/src/assetLoader.ts
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 replaces the external url-loader and file-loader dependencies with a custom internal assetLoader for SVG assets, removing legacy patches and the prebundling process. Feedback identifies a missing loader-utils dependency in package.json, a logic error in assetLoader.ts when handling function-based name templates, and the fragility of hardcoding the .mjs extension in the loader path.

Comment thread packages/plugin-svgr/package.json
Comment thread packages/plugin-svgr/src/assetLoader.ts
Comment thread packages/plugin-svgr/src/index.ts
@chenjiahan chenjiahan merged commit 1b311e9 into main Apr 11, 2026
10 checks passed
@chenjiahan chenjiahan deleted the chenjiahan/refactor-plugin-svgr-asset-loader branch April 11, 2026 12:22
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