前言
Create React App Configuration Override, an easy and comprehensible configuration layer for create-react-app.(Github)
React项目通过CRACO实现将增量添加配置
下载依赖
1
| npm install -D @craco/craco
|
添加配置文件
<project_name>/craco.config.js
Webpack配置
<project_name>/craco.config.js1 2 3 4 5
| module.exports = { "webpack": { ... } }
|
Less配置
下载依赖
1
| npm install -D @craco/craco craco-less
|
修改配置文件
<project_name>/craco.config.js1 2 3 4 5 6 7 8 9
| const CracoLessPlugin = require("craco-less");
module.exports = { plugins: [ { plugin: CracoLessPlugin } ] }
|
修改启动脚本
<project_name>/package.json1 2 3 4 5 6 7
| { "scripts": { "start": "craco start", "build": "craco build", "test": "craco test", } }
|
完成