【问题标题】:Cannot import inline-react-svg无法导入 inline-react-svg
【发布时间】:2020-06-24 10:47:31
【问题描述】:

我使用 Next.js + 和设计,在 .babelrc 中我导入了 Ant Design,但现在我不能使用 SVG 文件,我导入了 inline-react-svg,但后来我得到了错误 'Error :. plugins [0] [1] must be an object, false or undefined without this import代码,{"libraryName": "antd","style": true}一切正常

babelrc:

{
  "presets": [
    "next/babel"
  ],
  "plugins": [
    [
      "inline-react-svg",
      "import",
      {
        "libraryName": "antd",
        "style": true
      },
    ]
  ]
}

【问题讨论】:

    标签: svg babeljs next.js


    【解决方案1】:

    你能通过函数导入它们吗?

    export const Logo = (props) => (
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 180 27" {...props}>
        <path
          d="M112.2,9.6h-0.6v...z"
        />
      </svg>
    );
    

    然后

    import { Logo } from "../path/to/file"
    

    【讨论】:

      猜你喜欢
      • 2017-07-06
      • 1970-01-01
      • 2019-10-23
      • 2021-09-30
      • 2023-03-06
      • 1970-01-01
      • 2019-06-26
      • 1970-01-01
      相关资源
      最近更新 更多