使用create-react-app&antd搭建項目

1、安裝antd? ? ?npm install?antd

2、按需加載? ???npm install @craco/craco? ?

修改

/* package.json */

"scripts": {

????-? "start": "react-scripts start",

????-? "build": "react-scripts build",

????-? ?"test": "react-scripts test",

????+? "start": "craco start",

????+? "build": "craco build",

????+? "test": "craco test",

}

然后在項目根目錄創(chuàng)建一個?craco.config.js?用于修改默認(rèn)配置。

/* craco.config.js */

module.exports = {?

?// ...

};

3、less配置??npm install craco-less?


4、配置主題

并修改?craco.config.js?文件如下:

module.exports = {?

?????plugins: [?

?????????{?

?????????????plugin: CracoLessPlugin,?

?????????????????options: {?

?????????????????????lessLoaderOptions: {?

?????????????????????????lessOptions: {?

?????????????????????????????????modifyVars: {?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?????????'@primary-color': ????????'#1DA57A'?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?},

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?javascriptEnabled: true,?

? ? ? ? ? ? ? ? ? ? ? ? ? ?},?

? ? ? ? ? ? ? ? ? ? },?

?????????????},?

?????????},?

?????],

};

5、CSS模塊化


cssLoaderOptions:?{

??????????modules:?{?localIdentName:?"[local]_[hash:base64:5]"?}

}

tips:

? ? 1、可以把base64去掉直接顯示hash

? ? 2、css模塊化配置成功后,以對象形式使用樣式

? ? 3、全局樣式

eg:

? ? :glabol(.box){

????????width:50px;

? ? ? ? height:50px;

? ? ? ? borde:1px solid red;

????}

6、proxy配置

在craco.config.js文件中添加?


7、配置別名


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容