如何在不弹出的情况下将less集成到Create React App中

How to integrate less into Create React App without ejecting

我试过 react-app-rewire-less 模块,但它不起作用。

react-app-rewire-less-modules 但安装后 returns 出错

CRA 有一个 documentation for integrating SASS。您几乎可以将那里的 SASS 工具更改为 LESS 来实现您想要的。

这是我所做的:

我安装了 lessless-watch-compiler

yarn add less less-watch-compiler

然后将此行添加到 package.json

中的脚本中
"scripts": {
"watch-css": "less-watch-compiler src/ ./",
"start": "react-scripts start",

现在 运行

yarn watch-css

当我在src/App.less中进行更改时,会生成相应的src/App.css

react-app-rewire-less 有效。 我的问题是我导入了“name.less”而不是“./name.less”;

更新 同样对于那些正在寻找解决方案的人 - 你可以使用 craco