首页 前端知识 用customize-cra react-app-rewired配置less css module

用customize-cra react-app-rewired配置less css module

2024-02-29 12:02:49 前端知识 前端哥 472 264 我要收藏

1. 安装

npm i less less-loader -D
npm i customize-cra-less-loader -D

2.添加配置项

//config-overrides.js
const { override } = require('customize-cra');
const addLessLoader = require("customize-cra-less-loader");

module.exports = {
  webpack: override(
    addLessLoader({
      // strictMath: true,
      // noIeCompat: true,
      // loader: "css-loader",
      // options: {
      //   modules: {
      //     localIdentName: "[name]__[local]___[hash:base64:5]",
      //   },
      //   sourceMap: true
      // },
      // css loader options 
      cssLoaderOptions: {
        modules: {
          localIdentName: '[file]',
        }, 
      },
      // less loader options
      lessLoaderOptions: {
        lessOptions: {
          strictMath: true,
        }
      }
    }),
  )
}

// 需要下载customize-cra-less-loader,别从customize-cra直接导出,会报以下错误
ValidationError: Invalid options object. Less Loader has been initialized using an options object that does not match the API schema.

3.启动

npm start 
转载请注明出处或者链接地址:https://www.qianduange.cn//article/2923.html
标签
react.jsless
评论
会员中心 联系我 留言建议 回顶部
复制成功!