简体   繁体   English

Webpack:是否可以使用文件加载器加载svg? 如果是,怎么办?

[英]Webpack: Is it possible to load svg with the file-loader? If yes, how?

I want to load my svg via the file-loader with webpack. 我想通过webpack通过file-loader svg。 Is this even possible and if yes, how do I do that. 这是否可能,如果是,我该怎么做。

webpack.config.js webpack.config.js

test: /\.(jpe?g|png|gif|svg)$/i,
use: [
  {
    loader: 'file-loader',
    options: {
      name:'[name].[ext]',
      outputPath: 'img/',
      publicPath: '../',
    }
  }
]

I had similar problem. 我有类似的问题。 Just imported svg as html and then injected to your template as component. 只是将svg作为html导入,然后作为组件注入到模板中。 Worked perfectly for me. 为我完美地工作。

I found my fault, it was because I never used the svg in my project so it never got compiled. 我发现我的错,是因为我从未在项目中使用过svg,因此从未对其进行编译。 Now the file-loader compiles my svg too. 现在,文件加载器也可以编译我的svg。

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

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