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. 正则表达式检测IP地址与端口号是否合法

    正则表达式检测IP地址与端口号是否合法,代码如下: 正则表达式检测IP地址 public static bool CheckAddress(string s) { bool isLegal = fal ...

  2. form表单文件上传提交且接口回调显示提交成功

    前端: <form method="post" enctype="multipart/form-data" id="formSubmit&quo ...

  3. 用sublime cmd 快速打开hosts文件

      :: notepad start subl "%systemdrive%\WINDOWS\system32\drivers\etc\hosts"     文章来源:刘俊涛的博客 ...

  4. gdbhooks 栈信息

    https://devguide.python.org/gdb/ https://sourceware.org/gdb/current/onlinedocs/gdb/Python.html#Pytho ...

  5. DTServiceHubClient failed to bless service hub for simulator iPhone X (5C15AE72-12E2-475D-9C2B-EF...

    XCode跑不起模拟器,并报错:DTServiceHubClient failed to bless service hub for simulator iPhone X (5C15AE72-12E2 ...

  6. shell按月循环取数

    这里有个需求,按月查询,并且要输出每月的开始日期,结束日期. shell脚本如下: #!/bin/sh echo "0个参数时, 按月执行,默认当前月份 " echo " ...

  7. pip安装各种模块

    date: 2019-08-20   19:27:09 pip install requests pip install xpinyin pip install redis

  8. Flutter AspectRatio、Card 卡片组件

    Flutter AspectRatio 组件 AspectRatio 的作用是根据设置调整子元素 child 的宽高比. AspectRatio 首先会在布局限制条件允许的范围内尽可能的扩展,widg ...

  9. postgresql 所有聚合函数整理

    SELECT DISTINCT(proname) FROM pg_proc WHERE proisagg order by proname 查所有 SELECT * FROM pg_proc WHER ...

  10. ROS tf-数据类型

    博客参考:https://www.ncnynl.com/archives/201702/1305.html ROS与C++入门教程-tf-数据类型 说明: 介绍roscpp的Data Types(数据 ...