React 項目中使用create-react-app創建項目引入antd樣式不起作用的問題


//安裝babel-plugin-import
第一步:npm install babel-plugin-import --save
第二步:暴露webpack.config.js運行:npm run eject 注意:如果用git管理代碼,記得一定要提交才能安裝
第三步:在webpack.config.js中的module下的oneOf數組里加入下面代碼: {
              test: /(\.jsx|\.js)$/,               exclude: /node_modules/,               loader: 'babel-loader',               query:               {                 plugins: [                   [                     "import",                     { libraryName: "antd", style: 'css' }                   ] //antd按需加載                 ]               },             },             {//CSS處理               test: /\.css$/,               loader: "style-loader!css-loader?modules",               exclude: /node_modules/,             },             {//antd樣式處理               test: /\.css$/,               exclude: /src/,               use: [                 { loader: "style-loader", },                 {                   loader: "css-loader",                   options: {                     importLoaders: 1                   }                 }               ]             }, 重啟項目即可;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM