diff --git a/package.json b/package.json index 3cf22ae..2c69ea5 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "vue": "^3.2.33" }, "devDependencies": { + "@types/node": "^17.0.25", "@vitejs/plugin-vue": "^2.3.1", "typescript": "^4.6.3", "vite": "^2.9.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5fa476c..337ef92 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,6 +1,7 @@ lockfileVersion: 5.3 specifiers: + '@types/node': ^17.0.25 '@vitejs/plugin-vue': ^2.3.1 typescript: ^4.6.3 vite: ^2.9.5 @@ -11,6 +12,7 @@ dependencies: vue: 3.2.33 devDependencies: + '@types/node': 17.0.25 '@vitejs/plugin-vue': 2.3.1_vite@2.9.5+vue@3.2.33 typescript: 4.6.3 vite: 2.9.5 @@ -23,6 +25,10 @@ packages: engines: {node: '>=6.0.0'} hasBin: true + /@types/node/17.0.25: + resolution: {integrity: sha512-wANk6fBrUwdpY4isjWrKTufkrXdu1D2YHCot2fD/DfWxF5sMrVSA+KN7ydckvaTCh0HiqX9IVl0L5/ZoXg5M7w==} + dev: true + /@vitejs/plugin-vue/2.3.1_vite@2.9.5+vue@3.2.33: resolution: {integrity: sha512-YNzBt8+jt6bSwpt7LP890U1UcTOIZZxfpE5WOJ638PNxSEKOqAi0+FSKS0nVeukfdZ0Ai/H7AFd6k3hayfGZqQ==} engines: {node: '>=12.0.0'} diff --git a/tsconfig.json b/tsconfig.json index 7b568ca..85b1e03 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,13 @@ "dom" ], "skipLibCheck": true, - "types": ["vite/client"] + "types": ["vite/client"], + /** baseUrl 用来告诉编译器到哪里去查找模块,使用非相对模块时必须配置此项 */ + "baseUrl": ".", + // 非相对模块导入的路径映射配置,根据 baseUrl 配置进行路径计算 + "paths": { + "@/*": ["src/*"] + }, }, "include": [ "src/**/*.ts", diff --git a/vite.config.ts b/vite.config.ts index 315212d..91b3179 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,7 +1,16 @@ -import { defineConfig } from 'vite' -import vue from '@vitejs/plugin-vue' +import { ConfigEnv, UserConfigExport } from "vite" +import { resolve } from "path" +import vue from "@vitejs/plugin-vue" -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [vue()] -}) +/** 配置项文档:https://vitejs.dev/config */ +export default (env: ConfigEnv): UserConfigExport => { + return { + resolve: { + alias: { + /** @ 符号指向 src 目录 */ + "@": resolve(__dirname, "./src"), + }, + }, + plugins: [vue()], + } +}