vue loader different loaders for one extension

女生的网名这么多〃 提交于 2019-12-08 07:27:14

问题


I'm currently trying to use SVG in my vue-loader/webpack template project.

I need to load different kind of SVGs :
Icons : used inside my components and loaded with svg-inline loader for inlining and customization with css.
SVGImages : used inside img tag or background images loaded with url loader like the other images.

I tried the following configuration inside webpack.base.conf.js :

{
    test: /\.svg$/,
    oneOf: [
      {
        resourceQuery: /ico/, // image.svg?ico,
        use: 'svg-inline-loader'
      },
      {
        resourceQuery: '/normal/',
        use: 'url-loader'
      }
    ]
  }

But i have an error : You may need an appropriate loader to handle this file type.

The error is about an svg used in background image, the svg inline loader seems to be working fine.

Thanks for the help


回答1:


If you are trying to load an svg file without a query, then I think you should not use resoueceQuery. So:

{
    test: /\.svg$/,
    oneOf: [
      {
        resourceQuery: /ico/, // image.svg?ico,
        use: 'svg-inline-loader'
      },
      {
        use: 'url-loader'
      }
    ]
}

This should cover cases as follows:

  • image.svg?ico – svg-inline-loader
  • image.svg – url-loader
  • image.svg?foo – url-loader

Check this webpack issue for reference: https://github.com/webpack/webpack/issues/3497



来源:https://stackoverflow.com/questions/49383528/vue-loader-different-loaders-for-one-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!