Vite新建vue项目模板(自用)

初始化

创建项目

1
2
3
yarn create vite
cd ./module-name
yarn

引入常用依赖

功能

1
yarn add -S vue-router

界面

1
yarn add -D naive-ui

插件

1
2
3
yarn add -D unplugin-vue-components
yarn add -D unplugin-auto-import
yarn add -D @types/node

配置

vite.config.ts

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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { resolve } from 'path'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
Components({
resolvers: [NaiveUiResolver()]
}),
AutoImport({
imports: ['vue', 'vue-router',]
})
],
resolve: {
// 配置路径别名
alias: {
'@': resolve('./src'),
},
},
})

tsconfig.json

1
2
3
4
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}

router.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { createRouter, createWebHistory } from "vue-router";

const routes = [
{
path: '/',
name: 'index',
component: () => import('@/components/Index.vue')
}
]

const router = createRouter({
routes,
history: createWebHistory()
})

export default router

main.ts

1
2
3
4
5
6
7
8
9
import { createApp } from 'vue'
import App from './App.vue'
import router from '@/modules/router'

const app = createApp(App)
app.use(router)

app.mount('#app')

  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2020-2022 Eigeen
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信