在升级webpack4的时候,发现scss里面使用webpack定义的alias,都会爆路径错误
"webpack": "^4.6.0",
"node-sass": "^4.9.0",
"sass": "^1.3.2",
"sass-loader": "^7.0.1",
scss:
.icon {
background-image: url(~assets/images/mobile/common/broadcast.png);
}
webpack:
alias: {
'@': path.resolve(__dirname, '../src'),
'src': path.resolve(__dirname, '../src'),
'components': path.resolve(__dirname, '../src/components'),
'page': path.resolve(__dirname, '../src/page'),
'assets': path.resolve(__dirname, '../src/asstes'),
'store': path.resolve(__dirname, '../src/store'),
'utils': path.resolve(__dirname, '../src/utils'),
'libs': path.resolve(__dirname, '../src/libs')
}
结果:
我确定路径是没错的,不贴路径了,因为改成相对路径是没有问题的。这个问题,升级过的人,应该都会出现过,请问大家如何解决。
我记着webpack定义的alias只会改变js里的require和import,不影响样式导入