我已经使用create-react应用程序创建了一个react应用程序,而我对css的使用更少。我的应用程序构建正确,但没有一个较少的文件加载在构建/静态文件夹中
我使用customize-cra
和react-app-rewired
来为较少的文件添加加载程序。
config-overrides.js文件
const {
override,
addLessLoader
} = require('customize-cra');
const path = require('path');
module.exports = override(
addLessLoader({
paths: [path.resolve(__dirname, 'src/')],
javascriptEnabled: true,
sourceMap: true,
})
);
package.json 中的脚本
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test --passWithNoTests",
"eject": "react-scripts eject",
"release": "CI=true react-app-rewired test --coverage && npm run build && npm run package && npm run posttest",
},
依赖
"less": "^4.1.1",
"less-loader": "^8.0.0",
"react-scripts": "4.0.2",
"webpack": "4.44.2",
"customize-cra": "^1.0.0"
我得到的错误是Module build failed (from ./node_modules/less-loader/dist/cjs.js): TypeError: this.getOptions is not a function
引用了这篇文章,并将less loader的版本降低到5.0.0,它开始工作