一、安装sass-resources-loader
cnpm install sass-resources-loader --save-dev
二、修改build/utils.js
scss: generateLoaders('sass')
变成下面这样:
单个引入:
scss: generateLoaders('sass').concat(
{
loader: 'sass-resources-loader',
options: {
resources: path.resolve(__dirname, '../src/assets/scss/mixin.scss')
}
}
)
多个引入:
scss: generateLoaders('sass').concat({
loader: 'sass-resources-loader',
options: {
resources: [
path.resolve(__dirname, '../src/assets/scss/mixin.scss'),
path.resolve(__dirname, '../src/assets/scss/base.scss'),
]
}
}),
单个使用单独页面引入
往build文件中的webpack.base.conf.js中的module.rules中添加
{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
},
然后当前页面引入要用的单个scss
<style lang="scss" scoped>
@import url('../assets/scss/base.scss');
</style>