vue中背景图片以这样的方式引入,打包在生产环境中,图片404
.middle {
position: absolute;
top: 21%;
bottom: 25%;
background-color: aliceblue;
background: url('../assets/img/loginBg.png') 0 0 no-repeat;
}
解决方案
vue项目目录中/build/utils 47行左右
其中代码替换为
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
fallback: 'vue-style-loader',
publicPath: '../../'
})
} else {
return ['vue-style-loader'].concat(loaders)
}
vue项目目录中/config/index 60行左右
其中代码替换为
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: './',