Skip to content

Commit

Permalink
fix(module-tools): only invoke svgr in load hook (#5609)
Browse files Browse the repository at this point in the history
  • Loading branch information
10Derozan committed Apr 1, 2024
1 parent 4ca9f4c commit 5d135ea
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/poor-pandas-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/module-tools': patch
---

fix: only invoke svgr in load hook
fix: 只在 load hook 里调用 svgr 逻辑
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export async function getAssetContents(
typeof svgr === 'boolean' ? defaultConfig : _.merge(defaultConfig, svgr);

const filter = createFilter(config.include || SVG_REGEXP, config.exclude);
if (svgr && filter(assetPath)) {
if (svgr && filter(assetPath) && calledOnLoad) {
// svgr jsx-loader

// HACK: only support public path, the same as url-loader of webpack and rollup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ async function redirectImport(
// asset
const absPath = resolve(dirname(filePath), name);
const { contents: relativeImportPath, loader } =
await getAssetContents.apply(compiler, [absPath, outputDir]);
// HACK: set callOnLoad true to invoke svgr
await getAssetContents.apply(compiler, [absPath, outputDir, true]);
if (loader === 'jsx') {
// svgr
const ext = extname(name);
Expand Down

0 comments on commit 5d135ea

Please sign in to comment.