svg-sprite使用

export default {
  //  不使用 url-loader 的规则
  urlLoaderExcludes: [/\.(png|jpe?g|gif|svg)$/],
  chainWebpack(config, { webpack }) {
    //  svg 使用 file-loader 引入
    config.module.rule('svg-with-file')
      .test(/.svg$/)
      .use('svg-with-file-loader')
      .loader('file-loader')
      .options({
        name: 'svg/[name]-[hash:8].[ext]'
      });

    //  png|jpe?g|gif 使用 file-loader 引入
    config.module.rule('image-file')
      .test(/\.(png|jpe?g|gif)$/)
      .use('file-loader')
      .loader('file-loader')
      .options({
        name: 'images/[name]-[hash:8].[ext]'
      });
  }
}

参考

https://segmentfault.com/a/1190000015367490

猜你喜欢

转载自www.cnblogs.com/shangyueyue/p/10711734.html
今日推荐