Performance 下一个优化图像:错误模块解析失败,意外字符''&引用;

Performance 下一个优化图像:错误模块解析失败,意外字符''&引用;,performance,frontend,next.js,webpack-4,Performance,Frontend,Next.js,Webpack 4,我正在尝试用下一个优化的图像优化我的nextjs页面图像 这是next.config.js: module.exports = { ... withOptimizedImages: withOptimizedImages({ webpack(config) { config.resolve.alias.images = path.join(__dirname, 'public') return config } }), ... 以下是如何将图像导

我正在尝试用下一个优化的图像优化我的nextjs页面图像

这是next.config.js:

module.exports = {
...
  withOptimizedImages: withOptimizedImages({
    webpack(config) {
      config.resolve.alias.images = path.join(__dirname, 'public')
      return config
    }
  }),
...
以下是如何将图像导入组件:

require(`public/assets/icons/${iconName}`)
我的错误:

./public/assets/icons/website/information/hiring-black.svg 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
我正在使用最新版本的下一个优化图像,并尝试了不同的指南,但仍然没有运气。
请帮助

Next.js现在默认情况下优化图像。 参考:

如果需要svg,则需要尝试添加加载程序

安装:
纱线添加@svgr/webpack-D

要对此进行配置,请在
next.config.js

module.exports = {
  ...
  webpack(config) {
    config.module.rules.push({
      test: /\.svg$/,
      use: ['@svgr/webpack'],
    });

    return config;
  },
  ...
};

按如下方式使用:

...
import Star from './star.svg'
...
    <Star />
...

。。。
从“/Star.svg”导入星号
...
...

Next.js现在默认情况下优化图像。 参考:

如果需要svg,则需要尝试添加加载程序

安装:
纱线添加@svgr/webpack-D

要对此进行配置,请在
next.config.js

module.exports = {
  ...
  webpack(config) {
    config.module.rules.push({
      test: /\.svg$/,
      use: ['@svgr/webpack'],
    });

    return config;
  },
  ...
};

按如下方式使用:

...
import Star from './star.svg'
...
    <Star />
...

。。。
从“/Star.svg”导入星号
...
...