gpt4 book ai didi

webpack - 如何在Webpack中加载SVG图像?

转载 作者:行者123 更新时间:2023-12-04 08:23:15 24 4
gpt4 key购买 nike

我想在Webpack中使用svgo-loader加载SVG文件,但是出现以下错误:

ERROR in ./~/css-loader?modules&localIdentName=[name][local][hash:base64:5]!./~/autoprefixer-loader!./~/less-loader!./demo/src/components/App/components/Header/Header.less Module not found: Error: Cannot resolve module 'logo.svg' in /Users/mishamoroshko/react-autosuggest/demo/src/components/App/components/Header @ ./~/css-loader?modules&localIdentName=[name][local][hash:base64:5]!./~/autoprefixer-loader!./~/less-loader!./demo/src/components/App/components/Header/Header.less 6:199-218

ERROR in ./demo/src/components/App/components/Header/Header.less Module build failed: ModuleNotFoundError: Module not found: Error: Cannot resolve module 'logo.svg' in /Users/mishamoroshko/react-autosuggest/demo/src/components/App/components/Header



以下是相关的代码位:

Webpack配置
module: {
loaders: [
{
test: /\.less$/,
loader: ExtractTextPlugin.extract('style', 'css?modules&localIdentName=[name]__[local]___[hash:base64:5]!autoprefixer!less'),
exclude: /node_modules/
},
{
test: /\.svg$/,
loader: 'url?limit=8192!svgo'
},
...
]
}

package.json
"svgo": "^0.6.1",
"svgo-loader": "^1.1.0",
"url-loader": "^0.5.7",
...

Header.less
.logo {
background-image: url(./logo.svg);
}
logo.svgHeader.less位于同一目录中。

我在这里想念什么?

重现:
1. git clone git@github.com:moroshko/react-autosuggest.git
2. cd react-autosuggest
3. git checkout a5f1a99
4. npm install
5. npm start

最佳答案

This css-loader issue似乎相关。

解决方法是,更改:

background-image: url(./logo.svg);

至:
background-image: url(../parent-folder/logo.svg);

解决错误。

关于webpack - 如何在Webpack中加载SVG图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34480228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com