create-react-app 替代方案 react-app-rewired
npm install react-app-rewired customize-cra
customize-cra addLessLoader
报错问题:Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema. - options has an unknown property 'plugins'
customize-cra 官方问题解决
// 安装 版本 webpack5.5.0 , "react-app-rewired": "^2.2.1", "less": "^4.1.1", "less-loader": "^7.3.0",
// config-overrides.js 写法
module.exports = override(
addLessLoader({
// 必须如此书写
lessOptions: {
javascriptEnabled: true,
},
}),
// 添加此配置
adjustStyleLoaders(({ use: [, , postcss] }) => {
const postcssOptions = postcss.options;
postcss.options = { postcssOptions };
}),
)
// 改完重启项目