简体   繁体   English

在 Gatsby Typescript 中使用 SVG 时出错

[英]Error while using SVG in Gatsby Typescript

Here I'm trying to use SVG in Gatsby's Typescript page.在这里,我尝试在 Gatsby 的 Typescript 页面中使用 SVG。 I'm using this plugin https://www.gatsbyjs.com/plugins/gatsby-plugin-react-svg/ .我正在使用这个插件https://www.gatsbyjs.com/plugins/gatsby-plugin-react-svg/

//gatsby-config.js
        {
            resolve: "gatsby-plugin-react-svg",
            options: {
                rule: {
                    include: `${__dirname}/src/svg/`,
                },
            },
        },

//test.tsx
import React from "react";
import Layout from "../components/layout";
import { Container } from "../components/box";
import SEO from "../components/seo";
import ReactSvg from "../svg/react.svg" ;


export default () => (
    <Layout>
        <SEO title="404: Not found" />
        <Container>
            <ReactSvg />
        </Container>
    </Layout>
);

error I'm getting我得到的错误

The including rule for gatsby-plugin-react-svg is a regular expression that match a folder name (hence the slashes, /path/ ). gatsby-plugin-react-svg的包含规则是一个与文件夹名称匹配的正则表达式(因此是斜杠/path/ )。 Change it to:将其更改为:

    {
        resolve: "gatsby-plugin-react-svg",
        options: {
            rule: {
                include: `/svg/`,
            },
        },
    },

In addition, keep in mind that /svg/ must only contain SVG assets.此外,请记住/svg/必须仅包含 SVG 资产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM