Babel plugin for Create React App that enables named imports from non-JS assets like images, SVGs, and CSS modules. Current stable version is 0.3.8. Ships as part of react-scripts, so its release cadence matches CRA major versions. It transforms named import specifiers (e.g., { ReactComponent } from 'logo.svg') into static asset paths, thus requiring CRA-specific webpack configuration to work. Unlike direct asset require() calls, this plugin allows tree-shaking friendly imports. Note: only compatible with @babel/core ^7.1.0.
npm install babel-plugin-named-asset-importVerified import paths — ran on the pinned version, not inferred.
Shows basic usage with options configuration and custom loaderMap for SVG imports.
Use 'react-scripts@^4.0.0' or configure SVGR manually with webpack.
Use directly: @svgr/webpack for SVG components, asset modules for other files.
Ensure you use CRA's default webpack config or replicate loaderMap exactly.
Stick to 'ReactComponent' import or check CRA source code for supported queries.
npm install --save-dev babel-plugin-named-asset-import
Add the plugin to .babelrc and ensure webpack has appropriate rules (e.g., @svgr/webpack).
Check Babel config includes the plugin with valid loaderMap for svg.