参考文章
1.npm install node-sass --save-dev
2.npm install sass-resources-loader --save-dev
3.找到webpack.config.js
路径在:node_modules\react-scripts\config\webpack.config.js
4.初始代码
{
test: sassRegex,
exclude: sassModuleRegex,
use: getStyleLoaders(
{
importLoaders: 3,
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
},
'sass-loader'
),
sideEffects: true,
},
5.修改成这样
{
test: sassRegex,
exclude: sassModuleRegex,
use: getStyleLoaders(
{
importLoaders: 3,
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
},
'sass-loader'
).concat({
loader: 'sass-resources-loader',
options: {
resources: [
// 这里按照你的文件路径填写
path.resolve(__dirname, '../../../src/assets/style/common.scss')
]
}
}),
sideEffects: true,
},