-
下載組件庫包
yarn add antd
-
使用craco對create-react-app進行自定義配置
-
yarn add @craco/craco
-
根目錄創建craco.config.js文件
/* craco.config.js */ module.exports = { // ... };
-
更改package.json
"scripts": { "start": "craco start", "build": "craco build", "test": "craco test", "eject": "react-scripts eject" },
-
-
實現按需打包
-
yarn add babel-plugin-import
-
craco.config.js添加
babel:{ plugins: [ [ "import", { "libraryName": "antd", "libraryDirectory": "es", "style": true //設置為true即是less } ] ] }
-
-
實現自定義主題
-
yarn add craco-less
-
craco.config.js添加
module.exports = { plugins: [{ plugin: CracoLessPlugin, options: { lessLoaderOptions: { lessOptions: { modifyVars: { '@primary-color': '#1DA57A' }, javascriptEnabled: true, }, }, }, },], };
-