Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking change(svgr): disable mixed import by default #1815

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

chenjiahan
Copy link
Member

@chenjiahan chenjiahan commented Mar 13, 2024

Summary

Disable the mixed import of SVGR plugin by default.

What is mixed import

Mixed import refers to exporting an SVG file as a URL and a React component at the same time:

import logoUrl, { ReactComponent as Logo } from './logo.svg';

console.log(logoUrl); // -> string
console.log(Logo); // -> React component

Why not mixed import

  • Large bundle size: Mixed import results in a single SVG being compiled into two types of code, increasing the bundle size, and the default export cannot be tree-shaken.
  • Slow compilation: Mixed import causes additional compilation overhead. Even if the code does not use the ReactComponent export, it will still be compiled by SVGR. The compilation overhead of SVGR is high because it is based on babel.

Compatible with CRA

CRA allows the mixed import of SVG by default. For projects migrating from CRA, mixedImport can be manually enabled:

pluginSvgr({
  mixedImport: true,
});

Checklist

  • Tests updated.
  • Documentation updated.

@chenjiahan chenjiahan merged commit e9c8884 into main Mar 13, 2024
10 checks passed
@chenjiahan chenjiahan deleted the mixed_import_0313 branch March 13, 2024 06:13
@chenjiahan chenjiahan mentioned this pull request Mar 19, 2024
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.

1 participant