zoukankan      html  css  js  c++  java
  • react配置less步骤

    react配置less

    react官方标准脚手架中不支持less

    1.需要将配置抛出

    2.在webpack.config.js中更改配置

      

      a。const lessRegex = /.less$/;
      
      const lessModuleRegex = /.module.less$/;

      

      b。

      getStyleLoaders方法中添加less的loader
      c。
      modules中添加解析less

         

      代码粘贴

      const lessRegex = /.less$/;
      const lessModuleRegex = /.module.less$/;
      ——————————————————————————————————
      
    const getStyleLoaders = (cssOptions, lessOptions, preProcessor) => {
        const loaders = [
          isEnvDevelopment && require.resolve('style-loader'),
          isEnvProduction && {
            loader: MiniCssExtractPlugin.loader,
            // css is located in `static/css`, use '../../' to locate index.html folder
            // in production `paths.publicUrlOrPath` can be a relative path
            options: paths.publicUrlOrPath.startsWith('.')
              ? { publicPath: '../../' }
              : {},
          },
          {
            loader: require.resolve('css-loader'),
            options: cssOptions,
          },
          {
            loader: require.resolve('less-loader'),
            options: lessOptions,
          },
          {
            // Options for PostCSS as we reference these options twice
            // Adds vendor prefixing based on your specified browser support in
            // package.json
            loader: require.resolve('postcss-loader'),
            options: {
              // Necessary for external CSS imports to work
              // https://github.com/facebook/create-react-app/issues/2677
              ident: 'postcss',
              plugins: () => [
                require('postcss-flexbugs-fixes'),
                require('postcss-preset-env')({
                  autoprefixer: {
                    flexbox: 'no-2009',
                  },
                  stage: 3,
                }),
                // Adds PostCSS Normalize as the reset css with default options,
                // so that it honors browserslist config in package.json
                // which in turn let's users customize the target behavior as per their needs.
                postcssNormalize(),
              ],
              sourceMap: isEnvProduction && shouldUseSourceMap,
            },
          },
        ].filter(Boolean);
        if (preProcessor) {
          loaders.push(
            {
              loader: require.resolve('resolve-url-loader'),
              options: {
                sourceMap: isEnvProduction && shouldUseSourceMap,
              },
            },
            {
              loader: require.resolve(preProcessor),
              options: {
                sourceMap: true,
              },
            }
          );
        }
        return loaders;
      };
    ——————————————————————————————————————————————————————————————
    {
                  test: lessRegex,
                  exclude: lessModuleRegex,
                  use: getStyleLoaders({
                    importLoaders: 2,
                    sourceMap: isEnvProduction && shouldUseSourceMap,
                  },
                    'less-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: lessModuleRegex,
                  use: getStyleLoaders({
                    importLoaders: 2,
                    sourceMap: isEnvProduction && shouldUseSourceMap,
                    modules:true,
                    getLocalIdent: getCSSModuleLocalIdent,
                  },
                  'less-loader'
                  ),
                },
  • 相关阅读:
    SCU 4439 Vertex Cover|最小点覆盖
    SCU 4438 Censor|KMP变形题
    BZOJ 2152: 聪聪可可|点分治
    暑假集训-8.18总结
    AcWing 252. 树|点分治
    Proj THUDBFuzz Paper Reading: Field-aware Evolutionary Fuzzing Based on Input Specifications and Vulnerablity Metrics
    Proj THUDBFuzz Paper Reading: Semantic Fuzzing with Zest
    Proj THUDBFuzz Paper Reading: Smart Greybox Fuzzing
    Proj THUDBFuzz Paper Reading: Language-Agnostic Generation of Compilable Test Programs
    Proj THUDBFuzz Paper Reading: Fuzzing JS Engines with Aspect-preserving Mutation
  • 原文地址:https://www.cnblogs.com/zpsylgdx/p/12839219.html
Copyright © 2011-2022 走看看