1.安装需要用到的loader
npm install --save-dev node-sass@4.14.1 --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
npm install --save-dev sass-loader@7.3.1 --registry=https://registry.npm.taobao.org
2.使用
<style lang="scss">//注意!这里很关键,很多配置成了不编译就是漏了lang="scss"
@import '../assets/css/index.scss';
@import '../assets/css/base.scss';
@import '../assets/css/common.scss';
</style>
遇到的问题
报错:Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
解决办法:
1.查看node版本,对比下图,下载相应的版本。
node -v
根据node-sass选择对应的sass-loader。部分版本对应如下:
sass-loader 4.1.1,node-sass 4.3.0
sass-loader 7.0.3,node-sass 4.7.2
sass-loader 7.3.1,node-sass 4.7.2
sass-loader 7.3.1,node-sass 4.14.1
sass-loader 10.0.1,node-sass 6.0.1