这里主要讲解添加less  和  实现Antd按需加载

首选需要执行npm run eject 暴露所有内建的配置 ,这是后面所有配置的基础,这个必须优先执行!

一、实现Antd按需加载

按需加载插件。只需要引入模块即可,无需单独引入样式。

import {Button} from 'antd';
ReactDom.render(
<div>
<Button>
XXXX
</Button>
</div>);

1. 使用babel-plugin-import实现Antd按需加载,修改package.json,或者在项目根目录新建文件.babelrc写配置,注意是二选一。

首先执行以下命令安装 babel-plugin-import

npm install babel-plugin-import --save-dev

1)、修改package.json

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

2)、修改.babelrc

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

注意: 不要认为package.json里已有presets配置这里就不用写,这里的.babelrc会覆盖package.json里带有的babel配置,如果删除presets配置,会报错。

二、引入Less

1)安装less-loader 和 less

npm install less-loader less --save-dev

2)修改config文件夹下的webpack.config.dev.js和webpack.config.prod.js文件(都需要修改)
查找 :exclude
原本的 exclude: [/\.js$/, /\.html$/, /\.json$/],
修改为 exclude: [/\.html$/, /\.(js|jsx)$/, /\.(css|less)$/, /\.json$/, /\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],

查找:test: /.css$/
原本的 test: /\.css$/,
修改为 test: /\.(css|less)$/,

在这个test的下面找到use,添加loader

use: [
{...},
{...},
{
loader: require.resolve('less-loader') // compiles Less to CSS
}
]

参考地址:

https://blog.csdn.net/zhaoyu_m69/article/details/78800887

https://segmentfault.com/a/1190000012881473

https://blog.csdn.net/qq_35809834/article/details/72670220

二、create-react-app自定义配置的更多相关文章

  1. 如何扩展 Create React App 的 Webpack 配置

    如何扩展 Create React App 的 Webpack 配置  原文地址https://zhaozhiming.github.io/blog/2018/01/08/create-react-a ...

  2. 深入 Create React App 核心概念

    本文差点难产而死.因为总结的过程中,多次怀疑本文是对官方文档的直接翻译和简单诺列:同时官方文档很全面,全范围的介绍无疑加深了写作的心智负担.但在最终的梳理中,发现走出了一条与众不同的路,于是坚持分享出 ...

  3. 在 .NET Core 5 中集成 Create React app

    翻译自 Camilo Reyes 2021年2月22日的文章 <Integrate Create React app with .NET Core 5> [1] Camilo Reyes ...

  4. tap news:week5 0.0 create react app

    参考https://blog.csdn.net/qtfying/article/details/78665664 先创建文件夹 安装create react app 这个脚手架(facebook官方提 ...

  5. 使用create react app教程

    This project was bootstrapped with Create React App. Below you will find some information on how to ...

  6. Create React App

    Facebook开源了React前端框架(MIT Licence),也同时提供了React脚手架 - create-react-app. create-react-app遵循约定优于配置(Coc)的原 ...

  7. Create React App 安装less 报错

    执行npm run eject 暴露模块 安装 npm i  less less-loader -D 1.打开 react app 的 webpack.config.js const sassRege ...

  8. create react app的 css loader 进行局部配置

    { test: cssRegex, exclude: cssModuleRegex, use: getStyleLoaders({ importLoaders: 1, sourceMap: isEnv ...

  9. [React] Use the Fragment Short Syntax in Create React App 2.0

    create-react-app version 2.0 added a lot of new features. One of the new features is upgrading to Ba ...

  10. [React] {svg, css module, sass} support in Create React App 2.0

    create-react-app version 2.0 added a lot of new features. One of the new features is added the svgr  ...

随机推荐

  1. HDU-1711-Number Sequence(KMP)(Rabin-Karp)

    Rabin-Karp Accepted 1711 904MS 5272K 1310 B G++ #include "bits/stdc++.h" using namespace s ...

  2. 关于unicode汉字范围正则表达式的写法

    \u2E80-\u2EFF:CJK部首补充: \u2F00-\u2FDF:康熙部首: \u3000-\u303F:CJK标点符号: \u31C0-\u31EF:CJK笔划: \u3200-\u32FF ...

  3. 通过命令行创建Django项目

    只有安装的是pycharm专业版才可以直接在pycharm面板中直接创建Django项目 如果不是专业版,可以通过命令行创建Django项目 https://www.cnblogs.com/jiare ...

  4. Java - 面向对象练习 - market

    Marketpackage market; public class Market {    private String marname;    private Product[] producta ...

  5. Spring中@Resorce和@Autowired的区别

    @Resource的作用相当于@Autowired,只不过@Autowired按byType自动注入,而@Resource默认按 byName自动注入罢了.@Resource有两个属性是比较重要的,分 ...

  6. MyEclipse提示Errors occurred during the build

    最近在使用Extjs 在springsource Tool Suite运行时老是出现: Errors occurred during the build. Errors running builder ...

  7. tar:file-changed-as-we-read-it报错处理

    在使用tar命令对Mysql的数据目录进行备份打包时出现如下报错: tar cvzf mysql.tgz mysql /bin/tar: /path/to/mysql: file changed as ...

  8. 用Express 4和 MongoDB打造Todo List

    本篇文章主要參考自DreamersLab - 用Express和MongoDB寫一個todo list.原文的教學內容是使用Express 3.x版,在這邊做簡單Express 4.12.1的todo ...

  9. 2016/11/10 吃吃喝喝Hacking Thursday Night聚餐活动 at Dunkin Donuts

    店名:Dunkin Donuts 唐恩都乐 点评:http://www.dianping.com/shop/21378231 地址:静安区南京西路1649号静安公园内(近静安公园) 走法:地铁2号线静 ...

  10. codeblocks升级c++17版本

    用了大半年的codeblocks,今天居然发现我还不会配置MINGW版本,现在C++已经更新到c++20了,而我还在用c++11,所以今天记录一下怎么更新c++版本吧. 其实步骤没有我们想象的那么困难 ...