react腳手架(不同版本) webpack配置less 、antd


首先antd是基於less開發的,這里需要配置less

這里將 const cssRegex = /\.css$/ 
改成 const cssRegex = /\.(css|less)$/;

並配置以下loader

{
    loader: 'less-loader',
    options: {
        javascriptEnabled: true //如果你是less3.x的版本就加上這句話,不然就會報錯下圖
    }
},

不同的版本配置方式不同,本文以最新版本為例

{
  "name": "coupon-ui",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts": "2.1.8"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

使用 babel-plugin-import 配置問題

"babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [
      [
        "import",
        {
          "libraryName": "antd",
          "style": true
        }
      ]
    ]
  }
}


免責聲明!

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



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