如题。项目环境使用 webpack 构建的,webpack 这块配置的相关代码是
module: {
loaders: [
{ test: /\.(js|jsx)$/, exclude: /node_modules/, loader: 'babel' },
{ test: /\.less$/, exclude: /node_modules/, loader: 'style!css!postcss!less' },
{ test: /\.css$/, exclude: /node_modules/, loader: 'style!css!postcss' },
{ test:/\.(png|gif|jpg|jpeg|bmp)$/i, loader:'url-loader?limit=5000' }, // 限制大小5kb
{ test:/\.(png|woff|woff2|svg|ttf|eot)($|\?)/i, loader:'url-loader?limit=5000'} // 限制大小小于5k
]
},
项目中的 css 代码如下,其中引用的图片路径肯定是正确的,是一个开发环境下,图片相对于开发文件的相对路径。
li.jingdian {
background-image: url(./imgs/02jingdian_icon_1.png);
}
li.ktv {
background-image: url(./imgs/02KTVicon_2.png);
}
以上引用的两个图片都非常小,每个都 2kb 左右。
最终得到的效果如下。样式中看到有背景图片,但是就是没显示,何解?