在 webpack 配置中有这个:
module: {
rules: [
{
test: /\.svg$/,
use: ['@svgr/webpack'],
}
]
},
Run Code Online (Sandbox Code Playgroud)
和一个简单的导入组件
import Globe from './Globe.svg'
(...)
<div>
<Globe />
</div>
Run Code Online (Sandbox Code Playgroud)
导致整个页面呈现硬停止的以下错误。
Warning: <data:image/svg+xml;base64,ZnVuY3Rpb24gX2V... (more here)0.=87…
...BkZWZhdWx0IFN2Z0NvbXBvbmVudDs= /> is using incorrect casing.
Use PascalCase for React components, or lowercase for HTML elements.
Run Code Online (Sandbox Code Playgroud)
这似乎是已知问题https://github.com/smooth-code/svgr/issues/83。
我建议包括url-loader. https://www.smooth-code.com/open-source/svgr/docs/webpack/#using-with-url-loader-or-file-loader
在你的 webpack.config.js 中:
Run Code Online (Sandbox Code Playgroud){ test: /\.svg$/, use: ['@svgr/webpack', 'url-loader'], }在你的代码中:
Run Code Online (Sandbox Code Playgroud)import starUrl, { ReactComponent as Star } from './star.svg' const App = () => ( <div> <img src={starUrl} alt="star" /> <Star /> </div> )
| 归档时间: |
|
| 查看次数: |
1594 次 |
| 最近记录: |