1、Vite 需要 Node.js 版本 18+,20+
2、Vite 官网:https://cn.vitejs.dev/guide/
3、初始化项目
(1) npm create vite@latest
![](https://img.haomeiwen.com/i11830337/bc1ec718c218a221.png)
(2) 自定义create-vue
![](https://img.haomeiwen.com/i11830337/e8553121a530fab7.png)
(3)选项
![](https://img.haomeiwen.com/i11830337/919246d84ed68f0a.png)
4、初始化完有几个小问题
(1)找不到模块“vue”。你的意思是要将 "moduleResolution" 选项设置为 "node",还是要将别名添加到 "paths" 选项中?ts(2792)
![](https://img.haomeiwen.com/i11830337/39d51d9b7d5cea8e.png)
修复方法:
![](https://img.haomeiwen.com/i11830337/a920285920db7571.png)
"moduleResolution": "node",
(2)找不到模块“./App.vue”或其相应的类型声明。ts(2307)
![](https://img.haomeiwen.com/i11830337/2d072545f631233c.png)
修复方法:
![](https://img.haomeiwen.com/i11830337/d40eaaac1ad2a0b6.png)
找到env.d.ts添加:
declare module "*.vue" {
import type { DefineComponent } from "vue";
const vueComponent: DefineComponent<{}, {}, any>;
export default vueComponent;
}
(3)vite+vue3+ts ,类型“ImportMeta”上不存在属性“env”。ts(2339)
![](https://img.haomeiwen.com/i11830337/34889e672d5ad2b3.png)
修复方法:
![](https://img.haomeiwen.com/i11830337/025c1e415ea10bef.png)
interface ImportMetaEnv {
readonly BASE_URL: string
readonly VITE_APP_TITLE: string
// 更多环境变量...
}
interface ImportMeta {
readonly env: ImportMetaEnv
}
网友评论