1. 根路径别名@

1. npm run eject调出配置文件。找到webpack.config.js,搜索到,alias,在下面添加一行键值对'@':paths.appSrc,

      alias: {
// Support React Native Web
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
'react-native': 'react-native-web',
// Allows for better profiling with ReactDevTools
...(isEnvProductionProfile && {
'react-dom$': 'react-dom/profiling',
'scheduler/tracing': 'scheduler/tracing-profiling',
}),
...(modules.webpackAliases || {}),
'@':paths.appSrc,//ps:appSrc变量是该脚手架中已存在,可直接使用
},

2. 使用index.module.scss(scss+样式模块化)

开始百度搜索怎么在create-react-app中使用scss模块化,结果安装完scss直接可以使用了,无需改动配置,人家帮你配置好了,真方便。。

直接安装  npm i node-sass sass-loader
然后就可以这么用了: import styles from './index.module.scss'; ... <header className={styles.header}>

3.异步加载组件

npm install --save react-loadable

// 1.引入
import loadable from 'react-loadable';
import Loading from '@/components/Loading';
// import Index from '@/pages/Index';
// import IndexSort from '@/pages/IndexSort';

// 2.改造引入组件的方式
const Index = loadable({
loader:()=>import('@/pages/Index'),
loading:Loading,
});
const IndexSort = loadable({
loader:()=>import('@/pages/IndexSort'),
loading:Loading,
}); // 3.直接使用改造之后的组件
  {
      path: '/',
      exact:true,
      component: Index,
    },
    {
      path: '/index-sort',
      component: IndexSort,
    },
 

4.配置静态资源目录

在package.json中添加

"homepage":"."

 5.使用antd,按需加载

1. 调出配置文件

npm run eject

2.安装babel-plugin-import
npm -s install babel-plugin-import 3.在webpack.config.js中找到babel-loader,在options中的plugins的数组中添加一个成员 [
  require.resolve('babel-plugin-import'),// 导入 import 插件
  {
    libraryName: 'antd', //暴露antd
     style: 'css'
  }
]

更新中...

create-react-app中的一些功能配置的更多相关文章

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

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

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

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

  3. 深入 Create React App 核心概念

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

  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. android APP 中微信分享功能实现 的总结

    //花了很长时间最终完成了微信分享功能,中间走了很多弯路,在此做一下小结,希望对在应用中使用到微信分享的朋友有所帮助. 主要问题就是下面两个: 1.为什么运行了项目之后,微信分享只是闪了一下就没有了? ...

  8. Create React App 安装less 报错

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

  9. create react app 项目部署在Spring(Tomcat)项目中

    网上看了许多,大多数都是nginx做成静态项目,但是这样局限性太多,与Web项目相比许多服务端想做的验证都很麻烦,于是开始了艰难的探索之路,终于在不经意间试出来了,一把辛酸... 正常的打包就不说了. ...

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

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

随机推荐

  1. JVM 类加载器命名空间深度解析与实例分析

    一.创建Sample 1.创建实例 public class MyPerson { private MyPerson myPerson; public void setMyPerson(Object ...

  2. 【转载】 【Tensorflow】卷积神经网络中strides的参数

    原文地址: https://blog.csdn.net/TwT520Ly/article/details/79540251 http://blog.csdn.net/TwT520Ly -------- ...

  3. Qt tableview加载数据

    Qt tableview加载数据 //把数据加载到tableView void ImportData::loadDataInTableView() { ) { if (pageNum>stude ...

  4. 数据分析入门——numpy

    一.什么是numpy Numpy提供了一个在Python中做科学计算的基础库,重在数值计算,主要用于处理多维数组(矩阵)的库.用来存储和处理大型矩阵,比Python自身的嵌套列表结构要高效的多.本身是 ...

  5. [译]如何在GitHub仓库创建一个标签tag, 并推送到远程分支?

    问: 我在GitHub上有一个仓库,我需要给他打个tag.我在shell打了tag,但是在Github上没有显示出来.我还要做其他什么么? 我在shell中使用的命令是: git tag 2.0 当我 ...

  6. 【Leetcode_easy】876. Middle of the Linked List

    problem 876. Middle of the Linked List 参考 1. Leetcode_easy_876. Middle of the Linked List; 完

  7. React:快速上手(8)——前后端分离的跨域访问与会话保持

    React:快速上手(8)——前后端分离的跨域访问与会话保持 跨域访问 跨域是指从一个域名的网页去请求另一个域名的资源.比如从http://www.baidu.com/ 页面去请求http://www ...

  8. Python3-ibm_db模块-数据库操作之DB2

    官方文档 https://www.ibm.com/support/knowledgecenter/SSEPGG_9.5.0/kc_gen/developing-gen1.html 模块安装 Windo ...

  9. [BJOI2019] 删数 [dp转贪心结论+线段树]

    题面 传送门 思路 dp部分 以下称合法序列为原题面中可以删空的序列 这个是我在模拟考场上的思路 一开始我是觉得,这个首先可以写成一个dp的形式:$dp[i][j]$表示用$j$个数字填满了目标序列的 ...

  10. python 工具的URL

    Python取得大数据之后如何把数据图形化,之后让客户很清晰的看到你的结果 下面的图形化参照 matplotlib.3.0.2 https://matplotlib.org/gallery/index ...