Vite 是一个现代前端构建工具,旨在提高开发体验。它基于浏览器原生 ES 模块,使用 Rollup 打包,并优化了开发服务器。
特点
- 快速:Vite 的开发服务器使用
esbuild
,一个用 Go 编写的极快 JavaScript 打包器。 - 模块化:支持 ES 模块和 CommonJS,可以快速进行热替换(Hot Module Replacement)。
- 预配置:内置了多种预配置选项,易于上手。
安装
npm install --save-dev vite
使用
npx vite
示例
在 src
目录下创建一个 index.html
文件:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>示例</title>
</head>
<body>
<h1>欢迎来到 Vite 示例</h1>
</body>
</html>
运行 Vite 后,访问 http://localhost:3000
即可看到效果。
扩展阅读
更多关于 Vite 的信息,可以访问 Vite 官网。
Vite Logo