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'
                  ),
                },
  • 相关阅读:
    表单验证 validate 两种 一种是callback配合外部变量,当同步用。第2中是 then async await 这种 真正$api也适用
    Nginx 同时支持 http 和 https SSL 为了能有权限调取摄像头
    printJS 打印 无头无尾 style 加 @page { margin: 0; } body { padding: 100px;}
    Nginx 打不开 80端口占用 netstat -aon|findstr "80" 看有没有80占用 有的话 net stop http
    Selenium IDE 自动化测试 bug 会在console里面出 DevTools failed to load SourceMap 很不好,用完记得关掉这个程序
    async await $api vue
    electron打包踩过的坑总结 好文
    err => { err.name + ' ' + err.message 报错信息的调用
    跨域! dev: 'http://192.168.40.81:9090/xxx-api/' 平台和项目 两个都要改 要不会跨域!跨域!跨域!
    can do / will do / should do 情态动词
  • 原文地址:https://www.cnblogs.com/zpsylgdx/p/12839219.html
Copyright © 2011-2022 走看看