1.在 sass 中通过别名(@ 或 ~)引用需要指定路径
config/index.js
const path = require('path')
// NOTE 在 sass 中通过别名(@ 或 ~)引用需要指定路径
const sassImporter = function(url) {
if (url[0] === '~' && url[1] !== '/') {
return {
file: path.resolve(__dirname, '..', 'node_modules', url.substr(1))
}
}
const reg = /^@styles/(.*)/
return {
file: reg.test(url) ? path.resolve(__dirname, '..', 'src/styles', url.match(reg)[1]) : url
}
}
2.调用
const config = {
plugins: {
sass: {
importer: sassImporter
}
},
h5: {
sassLoaderOption: {
importer: sassImporter
}
},
}
.