React脚手架搭建过程

1:创建一个空文件夹

2:cmd空文件夹

3:因为npm默认从国外下载,为了下载速度,切换到国内的淘宝镜像

npm  config set registry https://registry.npm.taobao.org

4:查看是否切换成功

npm config get registry

5:安装react脚手架

npm i -g create-react-app

6:创建react

create-react-app progect(progect是项目名字文件夹)


Microsoft Windows [版本 10.0.17763.864]
(c) 2018 Microsoft Corporation。保留所有权利。

C:\Users\浪子\Desktop\react>
C:\Users\浪子\Desktop\react>npm config get registry
https://registry.npm.taobao.org/

C:\Users\浪子\Desktop\react>npm i -g create-react-app
C:\Users\浪子\AppData\Roaming\npm\create-react-app -> C:\Users\浪子\AppData\Roaming\npm\node_modules\create-react-app\index.js
+ create-react-app@3.2.0
updated 1 package in 6.111s

C:\Users\浪子\Desktop\react>create-react-app react_project

Creating a new React app in C:\Users\浪子\Desktop\react\react_project.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...


> core-js@2.6.10 postinstall C:\Users\浪子\Desktop\react\react_project\node_modules\babel-runtime\node_modules\core-js
> node postinstall || echo "ignore"


> core-js@3.2.1 postinstall C:\Users\浪子\Desktop\react\react_project\node_modules\core-js
> node scripts/postinstall || echo "ignore"

+ react-scripts@3.2.0
+ react@16.12.0
+ react-dom@16.12.0
added 1480 packages from 694 contributors in 184.767s

Success! Created react_project at C:\Users\浪子\Desktop\react\react_project
Inside that directory, you can run several commands:

  npm start
    Starts the development server.

  npm run build
    Bundles the app into static files for production.

  npm test
    Starts the test runner.

  npm run eject
    Removes this tool and copies build dependencies, configuration files
    and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

  cd react_project
  npm start

Happy hacking!

7:创建成功后,就可在对应的文件夹内看到所安装的文价包

8:进入对应的文件 启动react-app

指令:npm start
C:\Users\浪子\Desktop\react>cd react_project

C:\Users\浪子\Desktop\react\react_project>npm start

> react_project@0.1.0 start C:\Users\浪子\Desktop\react\react_project
> react-scripts start
Starting the development server...
Compiled successfully!

You can now view react_project in the browser.

  Local:            http://localhost:3000/
  On Your Network:  http://10.110.72.206:3000/

Note that the development build is not optimized.
To create a production build, use npm run build.

 

如图所示 即为创建成功 

### 使用 `create-react-app` 搭建 React 项目 #### 安装 Create React App 脚手架 为了确保使用最新版本的 `create-react-app` 构建工具,建议先更新全局安装的 `create-react-app`: ```bash npm install -g create-react-app ``` 验证安装成功以及当前版本号可以通过以下命令完成: ```bash create-react-app -V ``` 这一步骤有助于避免因旧版脚手架带来的潜在兼容性问题[^2]。 #### 创建项目 接下来,在目标目录下通过如下命令来创建一个新的 React + TypeScript 项目: ```bash npx create-react-app my-app --template typescript ``` 其中 `my-app` 是项目的名称,可以根据实际需求更改。该命令会自动下载必要的依赖项并配置好开发环境,包括 Webpack、Babel 和 ESLint 等常用工具链[^5]。 #### 启动开发服务器 一旦项目结构建立完毕,进入到项目根目录并通过下列指令启动本地开发服务: ```bash cd my-app npm start ``` 此时浏览器应自动打开页面展示默认的应用程序界面;如果未自动跳转,则可手动访问 http://localhost:3000 查看效果[^3]。 #### 修改和扩展功能 随着项目的推进,开发者可以在 src 文件夹内编辑组件代码或引入第三方库以实现更复杂的功能逻辑。对于本案例中的技术栈而言,推荐预先设定好的依赖包版本为: - Ant Design (antd): v5.4.7 - React: v18.2.0 - Redux Toolkit: v4.2.1 - React-Redux: v8.0.5 这些库能够有效提升用户体验的同时简化状态管理和UI设计的工作量[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值