学无先后,达者为师

网站首页 编程语言 正文

react全局scss变量

作者:郭俊强 更新时间: 2023-07-15 编程语言

 1、下载包

cnpm i sass-resources-loader -D

2、config中找到webpack.config.js

找到如下位置:

{
    test: sassRegex,
    exclude: sassModuleRegex,
    use: getStyleLoaders(
        {
            importLoaders: 3,
            sourceMap: isEnvProduction
                ? shouldUseSourceMap
                : isEnvDevelopment,
            modules: {
                mode: "icss",
            },
        },
        "sass-loader"
    ),
    // Don't consider CSS imports dead code even if the
    // containing package claims to have no side effects.
    // Remove this when webpack adds a warning or an error for this.
    // See https://github.com/webpack/webpack/issues/6571
    sideEffects: true,
},

替换:

{
    test: sassRegex,
    exclude: sassModuleRegex,
    use: getStyleLoaders(
        {
            importLoaders: 3,
            sourceMap: isEnvProduction
                ? shouldUseSourceMap
                : isEnvDevelopment,
            modules: {
                mode: "icss",
            },
        },
        "sass-loader"
    ).concat({
        loader:'sass-resources-loader',
        options:{
            resources:['./src/assets/scss/reset.scss','./src/assets/scss/gloab.scss']
        }
    }),
    // Don't consider CSS imports dead code even if the
    // containing package claims to have no side effects.
    // Remove this when webpack adds a warning or an error for this.
    // See https://github.com/webpack/webpack/issues/6571
    sideEffects: true,
},

3、重启项目即可

原文链接:https://blog.csdn.net/qq_37061571/article/details/131660739

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新