- npm init vite@latest
- 如果启动报错
error when starting dev server:
Error: getaddrinfo ENOTFOUND localhost
at GetAddrInfoReqWrap.onlookup [as oncomplete] (internal/dns/promises.js:42:17)
解决:
在终端输入:sudo vim /etc/hosts
先按 i 后,在最下面加上127.0.0.1 localhost
再:wq ,再重启项目
3.引入element-plus
3.1 pnpm install element-plus
3.2 pnpm install -D unplugin-vue-components unplugin-auto-import
报错:Internal server error: Failed to parse source for import analysis because the content contains inval:
看看vite.config.ts是不是把下面的东西删了
import vue from ‘@vitejs/plugin-vue’
// vite.config.ts
import { defineConfig } from ‘vite’
plugins: [
// …
vue(),
]
// 3.3vite.config.ts具体配置
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import path from 'path'
export default defineConfig({
// ...
plugins: [
// ...
vue(),
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
],
resolve:{
alias:{
'@':path.resolve(__dirname,'./src')
}
}
})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27