首页 > 解决方案 > 如何实现 Next.js SVG 加载器

问题描述

由于 Zeit 有一个新品牌,因此没有更新:

我的代码正在运行,现在由于这个问题我什至无法运行我的网站。如何以不同方式加载 SVG?我尝试使用 .babelrc 但没有用。

代码next.config.js

const withSass = require("@zeit/next-sass");
const withCSS = require("@zeit/next-css");

module.exports = withCSS(
  withSass({
    webpack(config, options) {
      config.module.rules.push({
        test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
        use: {
          loader: "url-loader",
          options: {
            limit: 100000,
          },
        },
      });
      return config;
    },
  })
);

标签: javascriptnext.jsvercel

解决方案


从 Next.js 9.3 开始,您可以使用内置的 CSS 和 SASS 支持。

有关详细信息,请参阅内置 SASS 支持

至于svg-您不需要装载机。

假设您有public/foo.svg图像,您可以在 CSS 中将其指定为url(/foo.svg).


推荐阅读