zoukankan      html  css  js  c++  java
  • create-react-app eject 之后 配置less

    // style files regexes下添加如下两个常量
     
    const lessRegex =/.less$/;
    const lessModuleRegex=/.module.less$/;
     
    如下
    // Check if TypeScript is setup
    const useTypeScript = fs.existsSync(paths.appTsConfig);
    
    // style files regexes
    const cssRegex = /.css$/;
    const cssModuleRegex = /.module.css$/;
    const sassRegex = /.(scss|sass)$/;
    const sassModuleRegex = /.module.(scss|sass)$/;
    
    //在此添加如下两个常量
    const lessRegex =/.less$/;
    const lessModuleRegex=/.module.less$/;
    
    // This is the production and development configuration.
    // It is focused on developer experience, fast rebuilds, and a minimal bundle.
    module.exports = function(webpackEnv) {

    {
    test: cssRegex,
    ....
    }
    后面
    仿照上面添加如下代码
    //在这之后仿照上面添加如下代码
                {
                    test: lessRegex,
                    exclude: lessModuleRegex,
                    use: getStyleLoaders(
                        {
                            importLoaders: 2,
                            sourceMap: isEnvProduction && shouldUseSourceMap,
                        },
                        'less-loader'
                    ),
                    sideEffects: true,
                  },
                  {
                    test: lessModuleRegex,
                    use: getStyleLoaders(
                        {
                            importLoaders: 2,
                            sourceMap: isEnvProduction && shouldUseSourceMap,
                            modules: true,
                            getLocalIdent: getCSSModuleLocalIdent,
                        },
                        'less-loader'
                    ),
                   
                  },

    代码如下:

    {
                  test: cssRegex,
                  exclude: cssModuleRegex,
                  use: getStyleLoaders({
                    importLoaders: 1,
                    sourceMap: isEnvProduction && shouldUseSourceMap,
                  }),
                  // 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,
                },
                // Adds support for CSS Modules (https://github.com/css-modules/css-modules)
                // using the extension .module.css
                {
                  test: cssModuleRegex,
                  use: getStyleLoaders({
                    importLoaders: 1,
                    sourceMap: isEnvProduction && shouldUseSourceMap,
                    modules: {
                      getLocalIdent: getCSSModuleLocalIdent,
                    },
                  }),
                },
    
                //在这之后仿照上面添加如下代码
                {
                    test: lessRegex,
                    exclude: lessModuleRegex,
                    use: getStyleLoaders(
                        {
                            importLoaders: 2,
                            sourceMap: isEnvProduction && shouldUseSourceMap,
                        },
                        'less-loader'
                    ),
                    sideEffects: true,
                  },
                  {
                    test: lessModuleRegex,
                    use: getStyleLoaders(
                        {
                            importLoaders: 2,
                            sourceMap: isEnvProduction && shouldUseSourceMap,
                            modules: true,
                            getLocalIdent: getCSSModuleLocalIdent,
                        },
                        'less-loader'
                    ),
                   
                  },
      
                // Opt-in support for SASS (using .scss or .sass extensions).
                // By default we support SASS Modules with the
                // extensions .module.scss or .module.sass
                {
                  test: sassRegex,
                  exclude: sassModuleRegex,
                  use: getStyleLoaders(
                    {
                      importLoaders: 3,
                      sourceMap: isEnvProduction && shouldUseSourceMap,
                    },
                    '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,
                },
                // Adds support for CSS Modules, but using SASS
                // using the extension .module.scss or .module.sass
                {
                  test: sassModuleRegex,
                  use: getStyleLoaders(
                    {
                      importLoaders: 3,
                      sourceMap: isEnvProduction && shouldUseSourceMap,
                      modules: {
                        getLocalIdent: getCSSModuleLocalIdent,
                      },
                    },
                    'sass-loader'
                  ),
                },
  • 相关阅读:
    bzoj 1051: [HAOI2006]受欢迎的牛
    bzoj 1192: [HNOI2006]鬼谷子的钱袋
    一些动规水题
    USACO 2014 Open Silver Fairphoto
    USACO 2013 Nov Silver Pogo-Cow
    09day1
    09day2
    08day2
    08day1
    07day2
  • 原文地址:https://www.cnblogs.com/webqiand/p/14012260.html
Copyright © 2011-2022 走看看