1.vite-config.ts
TypeScript
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import * as path from "path"
// https://vitejs.dev/config/
export default defineConfig({
base: '/',
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
}
},
})
2.注意是在tsconfig.app.json中添加,不是tsconfig.json
TypeScript
{
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"useDefineForClassFields": true,
"lib": [
"ES2020",
"DOM",
"DOM.Iterable"
],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
//------------------添加------------------
"baseUrl": "./",
"paths": {
"@/*": [
"src/*"
]
},
//------------------
},
"include": [
"src"
]
}