项目概况

Vite环境搭建

2026-01-292 min read前端技术
vue

unplugin-auto-import

text
1pnpm add unplugin-auto-import

vite.config.ts 中导入插件

vite.config.ts
1import {defineConfig} from 'vite' 2import vue from '@vitejs/plugin-vue' 3import AutoImport from 'unplugin-auto-import/vite' 4 5// https://vite.dev/config/ 6export default defineConfig({ 7 plugins: [vue(), AutoImport({ 8 include: [ 9 /.[tj]sx?$/, // .ts, .tsx, .js, .jsx 10 /.vue$/, 11 /.vue?vue/, // .vue 12 /.vue.[tj]sx??vue/, // .vue (vue-loader with experimentalInlineMatchResource enabled) 13 /.md$/, // .md 14 ], 15 imports: [ 16 'vue', 17 'vue-router', 18 'pinia' 19 ] 20 })], 21}) 22

tailwind

tailwind

bash
1pnpm add tailwindcss @tailwindcss/vite

vite.config.ts 中导入插件

vite.config.ts
1import {defineConfig} from 'vite' 2import vue from '@vitejs/plugin-vue' 3import AutoImport from 'unplugin-auto-import/vite' 4import tailwindcss from '@tailwindcss/vite' 5 6// https://vite.dev/config/ 7export default defineConfig({ 8 plugins: [vue(),tailwindcss()], 9}) 10

Prettier

vue-bits

bash
1npx jsrepo init https://vue-bits.dev/ui

初始化后会在本地生成配置文件

json
1{ 2 "$schema": "https://unpkg.com/jsrepo@2.4.3/schemas/project-config.json", 3 "repos": ["https://vue-bits.dev/ui"], 4 "includeTests": false, 5 "includeDocs": false, 6 "watermark": true, 7 "formatter": "prettier", 8 "configFiles": {}, 9 "paths": { 10 "*": "./src/vuebit" 11 } 12} 13

安装使用,空格选中,回车下载

bash
1npx jsrepo add

inspira-ui

shadcn-vue

安装 tailwindcss 依赖和插件

bash
1pnpm add tailwindcss @tailwindcss/vite 2 3pm add -D @types/node
style.css
1@import "tailwindcss";

配置别名

tsconfig.json
1{ 2 "files": [], 3 "references": [ 4 { "path": "./tsconfig.app.json" }, 5 { "path": "./tsconfig.node.json" } 6 ], 7 "compilerOptions": { 8 "baseUrl": ".", 9 "paths": { 10 "@/*": ["./src/*"] 11 } 12 } 13} 14 15```tsconfig.app.json 16{ 17 "extends": "@vue/tsconfig/tsconfig.dom.json", 18 "compilerOptions": { 19 "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", 20 "baseUrl": ".", 21 "paths": { 22 "@/*": [ 23 "./src/*" 24 ] 25 }, 26 /* Linting */ 27 "strict": true, 28 "noUnusedLocals": true, 29 "noUnusedParameters": true, 30 "erasableSyntaxOnly": true, 31 "noFallthroughCasesInSwitch": true, 32 "noUncheckedSideEffectImports": true 33 }, 34 "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"] 35} 36

添加 vite 插件依赖

vite.config.ts
1import path from 'node:path' 2import tailwindcss from '@tailwindcss/vite' 3import vue from '@vitejs/plugin-vue' 4import { defineConfig } from 'vite' 5 6export default defineConfig({ 7 plugins: [vue(), tailwindcss()], 8 resolve: { 9 alias: { 10 '@': path.resolve(__dirname, './src'), 11 }, 12 }, 13})

初始化

bash
1pnpm dlx shadcn-vue@latest init

安装inspira-ui

bash
1 pnpm dlx shadcn-vue@latest add "https://registry.inspira-ui.com/wavy-background.json"

页面跳转进度条

bprogress

text
1pnpm add @bprogress/vue
vue
1<script setup lang="ts"> 2import App from './App.vue' 3import { ProgressProvider } from '@bprogress/vue' 4</script> 5 6<template> 7 <ProgressProvider> 8 <App /> 9 </ProgressProvider> 10</template>

useProgress

vue
1<script setup lang="ts"> 2import { useProgress } from '@bprogress/vue'; 3 4const { start, stop, pause, resume } = useProgress(); 5</script> 6 7<template> 8 <button @click="start()">Start</button> 9 <button @click="stop()">Stop</button> 10 <button @click="pause">Pause</button> 11 <button @click="resume">Resume</button> 12</template>

nprogress

nprogress

text
1 NProgress.start() — shows the progress bar 2 3 NProgress.set(0.4) — sets a percentage 4 5 NProgress.inc() — increments by a little 6 7 NProgress.done() — completes the progress