- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用svgr's webpack plugin使用 create-react-app 到 use SVGs with MaterialUI's SvgIcon.我正在使用 craco将 svgr 添加到 Webpack 的配置中。
目前,每当应该渲染 SVG 时,都会抛出以下错误:
Failed to execute 'createElement' on 'Document': The tag name provided ('static/media/googlelogo.03ad8507.svg') is not a valid name.
const CracoAlias = require("craco-alias");
module.exports = {
plugins: [
{
plugin: CracoAlias,
options: {
baseUrl: "./src",
tsConfigPath: "./tsconfig.extend.json",
source: "tsconfig"
}
}
],
webpack: {
configure: (config, { env, paths }) => {
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"]
});
return config;
}
}
};
最佳答案
看起来 CRA 默认支持转换 SVG,从而使 craco+svgr 变得多余。
import { ReactComponent as GoogleLogo } from "../assets/images/googlelogo.svg";
GoogleLogo
现在是一个组件。
ReactComponent
是必需的魔法字符串。
关于webpack - 通过 craco 将 svgr 添加到 create-react-app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60074103/
我有一个带有 @svgr/webpack 的 Next.js 站点库安装。我已经配置了next.config.js与 @svgr/webpack 合作现在想要导入一个 svg 图像并将其与新的 nex
我正在尝试使用 SVGR第一次在 React 项目中能够将 .svg 文件作为组件导入。 使用 SVGR with Webpack 在我的 webpack 配置中配置了 SVGR 如下... {
将其添加到 webpack 配置中: module: { rules: [ { test: /\.svg$/, use: ['@svgr/web
我想用svgr's webpack plugin使用 create-react-app 到 use SVGs with MaterialUI's SvgIcon.我正在使用 craco将 svgr 添
我的第一个错误与描述的错误完全相同here 。我正在使用@svgr/webpack包将我的 .svg 文件导入为 React 组件,如下所示: import Shop from './icons/sh
Webpack 配置: 对于 .svg 我使用 config:{ test:/\.svg$/, use: ['svgr/webpack'] } 对于 .scss,我使用 css-loader、post
我是一名优秀的程序员,十分优秀!