如何配置以减少 React 的工作量?

问题描述

这是一个用 react CLI 创建的新项目。 我做了什么:

  1. 首先,运行 npm run eject
  2. 运行npm i less less-loader
  3. 修改 webpack.config
const cssRegex = /\.(css|less)$/;
const cssModuleRegex = /\.module\.(css|less)$/;

 // "postcss" loader applies autoprefixer to our CSS.
            // "css" loader resolves paths in CSS and adds assets as dependencies.
            // "style" loader turns CSS into JS modules that inject <style> tags.
            // In production,we use MiniCSSExtractPlugin to extract that CSS
            // to a file,but in development "style" loader enables hot editing
            // of CSS.
            // By default we support CSS Modules with the extension .module.css
            {
              test: cssRegex,exclude: cssModuleRegex,use: getStyleLoaders({
                importLoaders: 2,sourceMap: isEnvProduction
                  ? shouldUseSourceMap
                  : isEnvDevelopment,modules: true,},'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,
  1. npm 启动 我得到了一个错误
Failed to compile.

./src/index.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--5-oneOf-4-3!./node_modules/less-loader/dist/cjs.js??ref--5-oneOf-4-4!./src/index.css)
TypeError: this.getoptions is not a function

我错过了什么吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)