Vue-cli configuration Webpack

want to add the following configuration to Webpack:
(svg files in src/icons are loaded with svg-sprite-loader, and svg in other folders are loaded with url-loader)

      {
        test: /\.svg$/,
        loader: "svg-sprite-loader",
        include: [resolve("src/icons")],
        options: {
          symbolId: "icon-[name]"
        }
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: "url-loader",
        exclude: [resolve("src/icons")],
        options: {
          limit: 10000,
          name: utils.assetsPath("img/[name].[hash:7].[ext]")
        }
      },
When

vue-cli < v3.0.0, you can modify it directly in webpack.base.conf.js.
but in vue-cli v3.0.0, the configuration mode has changed.
follow the ide/webpack.md" rel=" nofollow noreferrer "> document but still haven"t changed it for a long time

.

now vue.config.js is written like this (does not run correctly):

const path = require("path")

function resolve(dir) {
  return path.join(__dirname, "..", dir)
}

module.exports = {
    chainWebpack: config => {
    // loader
    config.module
      .rule("svg")
      .test(/\.svg$/)
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      //.include([resolve("src/icons")])
      .options({ symbolId: "icon-[name]" })
      .end()
    // loader
    config.module
      .rule("svg")
      .test(/\.(png|jpe?g|gif|svg)(\?.*)?$/)
      .use("url-loader")
      .loader("url-loader")
      .tap(exclude => {
        exclude = [resolve("src/icons")]
        return exclude
      })
  }
}
Mar.24,2021

is the same ide/webpack.md-sharpreplacing-loaders-of-a-rule" rel=" nofollow noreferrer "> document .. There is a rule replacement method in it

load uniformly with svg-sprite-loader for the time being, and then take a look at the partition folder.

module.exports = {
  chainWebpack: config => {
    const svgRule = config.module.rule('svg')

    // clear all existing loaders.
    // if you don't do this, the loader below will be appended to
    // existing loaders of the rule.
    svgRule.uses.clear()

    // add replacement loader(s)
    svgRule
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
  }
}

this is fine. And write include and exclude before use and loader

module.exports = {
    chainWebpack: config => {
        config.module
            .rules
            .delete('svg')

        config.module
            .rule('svg')
            .test(/\.(svg)(\?.*)?$/)
            .include
            .add(resolve('src/icons'))
            .end()
            .use('svg-sprite-loader')
            .loader('svg-sprite-loader')
            .options({
                symbolId: 'icon-[name]'
            })
    }
}
Menu