当前位置: 首页 > news >正文

❤️ React的安装和使用(实战篇)

React的安装和使用

一、React的安装和使用

reactJs警告提示:
This version of tar is no longer supported, and will not receive security updates. Please upgrade asap

翻译:tar@2.2.2:此版本的tar不再受支持,将不会收到安全更新。请尽快升级。

简而言之:tar@2.2.2过期
运行:npm install -g tar
tar的版本更新到最新

检查React版本是否安装:

create-react-app -V

在这里插入图片描述

显示我的版本已经安装成功,猜测可能是安装成功再次安装给的提示!

二、创建项目并运行

1、 创建 react 项目2、进入到项目里 
cd my-app3、安装 less 及 loader
yarn add -D less less-loader4、将 webpack 配置暴露出来
yarn eject5、打开 /config/webpack.config.js
全局搜索 style files regexes 找到如下代码位置// style files regexes
const cssRegex = /\.css$/
const cssModuleRegex = /\.module\.css$/
const sassRegex = /\.(scss|sass)$/
const sassModuleRegex = /\.module\.(scss|sass)$/6、在这个代码的下边添加两行 less 的配置
// style files regexes
const cssRegex = /\.css$/
const cssModuleRegex = /\.module\.css$/
const sassRegex = /\.(scss|sass)$/
const sassModuleRegex = /\.module\.(scss|sass)$/const lessRegex = /\.less$/ // 新添加的
const lessModuleRegex = /\.module\.less$/ // 新添加的7、全局搜索 test: sassModuleRegex,找到如下代码位置:// Adds support for CSS Modules, but using SASS// using the extension .module.scss or .module.sass{test: sassModuleRegex,use: getStyleLoaders({importLoaders: 3,sourceMap: isEnvProduction? shouldUseSourceMap: isEnvDevelopment,modules: {mode: 'local',getLocalIdent: getCSSModuleLocalIdent,},},'sass-loader'),},// "file" loader makes sure those assets get served by WebpackDevServer.// When you `import` an asset, you get its (virtual) filename.// In production, they would get copied to the `build` folder.// This loader doesn't use a "test" so it will catch all modules// that fall through the other loaders.{// Exclude `js` files to keep "css" loader working as it injects// its runtime that would otherwise be processed through "file" loader.// Also exclude `html` and `json` extensions so they get processed// by webpacks internal loaders.exclude: [/^$/, /\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],type: 'asset/resource',},9、添加 less 的 loader 就完成了// Adds support for CSS Modules, but using SASS// using the extension .module.scss or .module.sass{test: sassModuleRegex,use: getStyleLoaders({importLoaders: 3,sourceMap: isEnvProduction? shouldUseSourceMap: isEnvDevelopment,modules: {mode: 'local',getLocalIdent: getCSSModuleLocalIdent,},},'sass-loader'),},// ------------- 从这里往下都是添加的行{test: lessRegex,exclude: lessModuleRegex,use: getStyleLoaders({importLoaders: 2,sourceMap: isEnvProduction? shouldUseSourceMap: isEnvDevelopment,},'less-loader'),// Don't consider CSS imports dead code even if the// containing package claims to have no side effects.// Remove this when webpack adds a warning or an error for this.// See https://github.com/webpack/webpack/issues/6571sideEffects: true,},{test: lessModuleRegex,use: getStyleLoaders({importLoaders: 2,sourceMap: isEnvProduction && shouldUseSourceMap,modules: {getLocalIdent: getCSSModuleLocalIdent,},},'less-loader'),},// ------------- 从这里往上都是添加的行// "file" loader makes sure those assets get served by WebpackDevServer.// When you `import` an asset, you get its (virtual) filename.// In production, they would get copied to the `build` folder.// This loader doesn't use a "test" so it will catch all modules// that fall through the other loaders.{// Exclude `js` files to keep "css" loader working as it injects// its runtime that would otherwise be processed through "file" loader.// Also exclude `html` and `json` extensions so they get processed// by webpacks internal loaders.exclude: [/^$/, /\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],type: 'asset/resource',},10、配置结束
直接在项目里引入一个 less 文件,就可以正常的使用了

三、写出一个hello,word组件

相关文章:

  • Redis-使用java代码操作Redis
  • LangChain+LLM实战---向量数据库介绍
  • Langchain-Chatchat-win10本地安装部署成功笔记(CPU)
  • 基于.NET、Uni-App开发支持多平台的小程序商城系统 - CoreShop
  • Mybatis-Plus自动填充功能配置和使用 [MyBatis-Plus系列] - 第494篇
  • 设计模式之策略模式(Strategy)
  • hdlbits系列verilog解答(always块case语句2)-34
  • Kotlin 进阶函数式编程技巧
  • Node.js、Chrome V8 引擎、非阻塞式I/O介绍
  • 面试问题?
  • Mac苹果电脑分辨率修改管理 安装SwitchResX 完美解决
  • RISC-V处理器设计(四)—— Verilog 代码设计
  • leetcode做题笔记215. 数组中的第K个最大元素
  • 软件开发必备神器!一文读懂10款热门看板工具推荐!
  • [尚硅谷React笔记]——第9章 ReactRouter6
  • 【知识碎片】第三方登录弹窗效果
  • 2018天猫双11|这就是阿里云!不止有新技术,更有温暖的社会力量
  • 2018一半小结一波
  • egg(89)--egg之redis的发布和订阅
  • github指令
  • GitUp, 你不可错过的秀外慧中的git工具
  • Java 9 被无情抛弃,Java 8 直接升级到 Java 10!!
  • Javascript弹出层-初探
  • Redis 懒删除(lazy free)简史
  • Solarized Scheme
  • Vue组件定义
  • 编写高质量JavaScript代码之并发
  • 开源中国专访:Chameleon原理首发,其它跨多端统一框架都是假的?
  • 前端技术周刊 2019-02-11 Serverless
  • 十年未变!安全,谁之责?(下)
  • 2017年360最后一道编程题
  • 京东物流联手山西图灵打造智能供应链,让阅读更有趣 ...
  • ​DB-Engines 12月数据库排名: PostgreSQL有望获得「2020年度数据库」荣誉?
  • ​ssh-keyscan命令--Linux命令应用大词典729个命令解读
  • #LLM入门|Prompt#1.7_文本拓展_Expanding
  • #NOIP 2014#Day.2 T3 解方程
  • #微信小程序:微信小程序常见的配置传值
  • #我与Java虚拟机的故事#连载02:“小蓝”陪伴的日日夜夜
  • (1)SpringCloud 整合Python
  • (4) PIVOT 和 UPIVOT 的使用
  • (4)事件处理——(2)在页面加载的时候执行任务(Performing tasks on page load)...
  • (二)构建dubbo分布式平台-平台功能导图
  • (论文阅读30/100)Convolutional Pose Machines
  • (切换多语言)vantUI+vue-i18n进行国际化配置及新增没有的语言包
  • (原)本想说脏话,奈何已放下
  • ***利用Ms05002溢出找“肉鸡
  • .net 4.0发布后不能正常显示图片问题
  • .NET Core 网络数据采集 -- 使用AngleSharp做html解析
  • .vollhavhelp-V-XXXXXXXX勒索病毒的最新威胁:如何恢复您的数据?
  • @TableLogic注解说明,以及对增删改查的影响
  • [ C++ ] STL priority_queue(优先级队列)使用及其底层模拟实现,容器适配器,deque(双端队列)原理了解
  • [ CTF ] WriteUp- 2022年第三届“网鼎杯”网络安全大赛(白虎组)
  • [ vulhub漏洞复现篇 ] Jetty WEB-INF 文件读取复现CVE-2021-34429
  • [ 代码审计篇 ] 代码审计案例详解(一) SQL注入代码审计案例
  • [ 云计算 | AWS 实践 ] 基于 Amazon S3 协议搭建个人云存储服务