【发布时间】:2018-09-21 14:01:46
【问题描述】:
我在 React 中上传 SVG 图标时遇到问题。我将 svg-inline-loader 添加到 webpack,但它没有显示图标。它只是显示未找到的图片。我想将 SVG 图标添加为 img src、背景图像和快捷方式图标。
编辑:
这是我的 webpack.config
module.exports = {
entry: ["whatwg-fetch", "./js/app.jsx"],
output: {
filename: "./js/out.js"
},
devServer: {
inline: true,
contentBase: './',
port: 3001
},
watch: true,
module: {
loaders: [{
test: /\.jsx$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015','stage-2', 'react']
}
}, {
test: /\.scss$/,
loader: ['style-loader', 'css-loader', 'sass-loader']
},
{
test: /\.(png|jpg|gif)$/,
exclude: /node_modules/,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name].[ext]'
}
}
]
},
{
test: /\.svg$/,
loader: 'svg-inline-loader'
}
]
}
};
【问题讨论】:
-
您可以随时将 svg 文件更改为 jsx 文件。是否需要向您展示如何?
-
好吧,我以前从来没有使用过svg文件,所以我不知道如何:/