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