react引入sass公共样式不生效

参考文章
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,
},

上一篇:Solving environment: failed with repodata from current_repodata.json, will retry with next repodata


下一篇:java中的本地缓存