npm run dev # vite
Vite 做的事:
启动 Node 开发服务器
拦截所有请求
遇到 .ts、.jsx、.vue 等用 esbuild 或插件 transform 成 JS
遇到 .css 转成 JS 注入 <style>
浏览器加载模块时使用原生 ESM:
import App from './App.vue'
你写:
<template><h1>{{ msg }}</h1></template>
<script setup lang="ts">
const msg: string = 'Hello world'
</script>
Vite 插件系统(比如 @vitejs/plugin-vue):
.vue 文件拆成 template/script/stylerender 函数最终浏览器收到的是 JS 模块,类似:
export default {
render() { return h('h1', null, 'Hello world') }
}
Vite 会用 WebSocket 通知浏览器:
“文件变了,重载这个模块”