Vite创建React项目,另外一种更加简单的方法

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

Vite创建React项目,另外一种更加<a href=https://www.elefans.com/category/jswz/34/1770983.html style=简单的方法"/>

Vite创建React项目,另外一种更加简单的方法

在上一篇blog中一个一个安装依赖dependencies,有没有一步到位的方法呢,有!

参考《React 18 Design Patterns and Best Practices Design, build, and deploy production-ready web applications with React》4th 第一章倒数第二节Vite as a solution有个脚手架工具create-vite来帮助我们快速构建React by Vite(npm install不行就yarn add):

1.全局安装ta:

npm install -g create-vite

2.创建项目my-react-app,指定模板为ts版的react,更多模板可看npm官网介绍

create-vite my-react-app --template react-ts

3.cd到目录里&安装依赖

cd my-react-app
npm install
npm run dev

4.运行成功后可以访问localhost:5173查看效果

5.想修改默认端口,可以到vite.config.ts中添加server和指定port为3000:

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";// /config/
export default defineConfig({plugins: [react()],server: {port: 3000,},
});

无需重启项目,访问localhost:3000即可

更多推荐

Vite创建React项目,另外一种更加简单的方法

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

发布评论

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

>www.elefans.com

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