简体   繁体   English

如何实现 Next.js SVG 加载程序

[英]How to implement a Next.js SVG Loader

since Zeit has a new brand, there are no updates for:由于 Zeit 有一个新品牌,因此没有更新:

  • @zeit/with-css @zeit/with-css
  • @zeit/with-sass @zeit/with-sass

My code was working and now I can't even run my website due to that problem.我的代码正在运行,现在由于这个问题我什至无法运行我的网站。 How can I load SVG differently?如何以不同方式加载 SVG? I tried using.babelrc but didn't work.我试过 using.babelrc 但没有用。

The code next.config.js :代码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;
    },
  })
);

Since Next.js 9.3 you can use built-in CSS and SASS support.从 Next.js 9.3 开始,您可以使用内置的 CSS 和 SASS 支持。

See Built-in SASS support for more information.有关详细信息,请参阅内置 SASS 支持

As for svg - you don't need a loader for it.至于svg - 你不需要装载机。

Assuming you have public/foo.svg image you can specify it in CSS as url(/foo.svg) .假设您有public/foo.svg图像,您可以在 CSS 中将其指定为url(/foo.svg)

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

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