Vite 最小项目
1、项目初始化
- 创建项目
my-project,安装 Vite
npminstallvite --save-dev
- 完善项目结构
my-project/ ├── node_modules/ ├── package.json ├── package-lock.json ├── index.html └── src/ └── main.js
- package.json,配置项目
{"scripts":{"dev":"vite","build":"vite build"}}
2、代码编写
- index.html
<!doctypehtml><htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><title>index</title></head><body><divid="app"></div><scripttype="module"src="/src/main.js"></script></body></html>
- main.js
console.log("项目启动");constapp=document.querySelector("#app");if(app){app.innerHTML="<h3>Hello Vite</h3>";}
3、项目运行
- 启动开发者服务器
npmrun dev
- 项目打包
npmrun build