Vite是什么
Vite是一个开发环境工具,旨在提高我们的开发速度。
最近俺看了一下尤雨溪大大在B站上的直播,直播中他也谈到了这款工具,最近花了很多精力在做这件事情。
在尤玉溪推特上也可以看到相关的推文:
As I was going to bed, I had an idea about a no-bundler dev setup (using native browser ES imports), but with support for Vue SFCs **with hot reload**. Now it’s almost 6AM and I have PoC working. The hot reload is so fast it’s near instant.尤大大Twitter
本质上是利用了浏览器对于script标签type=”module”会发送一个请求。
Vite允许您使用单文件组件开发Vue应用程序,而不需要任何捆绑步骤。导入是浏览器作为本地ES模块导入请求的。
开发环境服务器拦截对.
实践
我们创建以下文件:
Comp.vue
{ { count }}
export default {
data: () => ({ count: 0 })
}
button{
font-size: 2rem;
}
index.html
import { createApp } from 'vue'
import Comp from './Comp.vue'