Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在webpack 4弹出的react应用程序中添加较少配置时出错_Reactjs_Webpack_Less - Fatal编程技术网

Reactjs 在webpack 4弹出的react应用程序中添加较少配置时出错

Reactjs 在webpack 4弹出的react应用程序中添加较少配置时出错,reactjs,webpack,less,Reactjs,Webpack,Less,嗨,我弹出了CRA来添加更少的配置,但我得到了这样的错误 (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-3-1!./node_modules/less-loader/dist/cjs.js??ref--6-oneOf-3-2!./node_modules/postcss-loader/src??postcss!./src/index.css) Webpackversion-4,我添加了较少的配置,但出现了错误,而且我安装了引导css,

嗨,我弹出了CRA来添加更少的配置,但我得到了这样的错误

(./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-3-1!./node_modules/less-loader/dist/cjs.js??ref--6-oneOf-3-2!./node_modules/postcss-loader/src??postcss!./src/index.css)
Webpackversion-4,我添加了较少的配置,但出现了错误,而且我安装了引导css,它也出现了类似{在cli中丢失}的错误

  const getStyleLoaders = (cssOptions, preProcessor) => {
    const loaders = [
      isEnvDevelopment && require.resolve('style-loader'),
      isEnvProduction && {
        options: paths.publicUrlOrPath.startsWith('.')
          ? { publicPath: '../../' }
          : {},
      },
      {
        loader: require.resolve('css-loader'),
        options: cssOptions,
      },
      {
        loader: require.resolve('less-loader'), //added less here
        options: cssOptions,
      },
      {
        loader: require.resolve('postcss-loader'),
        options: {
          ident: 'postcss',
          plugins: () => [
            require.resolve('autoprefixer'),
            require('postcss-flexbugs-fixes'),
            require('postcss-preset-env')({
              autoprefixer: {
                flexbox: 'no-2009',
              },
              stage: 3,
            }),
            postcssNormalize(),
          ],
          sourceMap: isEnvProduction && shouldUseSourceMap,
        },
      },
下定决心

    //less loader
    {
      test:'/\.less$/',
      include: lessModuleRegex,
      use: getStyleLoaders({
        importLoaders: 1,
        sourceMap: isEnvProduction && shouldUseSourceMap,
      },
      'less-loader'
      ),
      sideEffects: true,
    },
    {
      test: /\.module\.less$/,
      use: getStyleLoaders({
        importLoaders: 1,
        sourceMap: isEnvProduction && shouldUseSourceMap,
        modules: {
          getLocalIdent: getCSSModuleLocalIdent,
        },
      },
      'less-loader'
      ),
    },

如何在CRA中添加较少的内容?

对我来说,通过添加此规则解决了问题,只需在webpack.config.js中添加更多内容即可:

另外,请确保您使用的是最新版本的less loader

           {
              test: /\.less$/,
              use: getStyleLoaders(
                {
                  importLoaders: 3,
                  sourceMap: isEnvProduction && shouldUseSourceMap,
                  modules: {
                    getLocalIdent: getCSSModuleLocalIdent,
                  },
                },
                'less-loader'
              ),
            },