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

编程入门 行业动态 更新时间:2024-10-09 03:32:09

❤️ React的安装和使用(<a href=https://www.elefans.com/category/jswz/34/1769979.html style=实战篇)"/>

❤️ 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 : 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组件

更多推荐

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

本文发布于:2023-11-16 11:17:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620569.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实战篇   React

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!