Vue3+Ts+Vite project (Part 4) - Configure @ path alias and implement @ instead of /src

1. Configuration in the vite.config.ts file in the root directory

Insert image description here

import {
    
     resolve } from 'path';
resolve: {
    
    
  // 设置文件./src路径为 @
  alias: [
    {
    
    
      find: '@',
      replacement: resolve(__dirname, './src')
    }
  ]
}

2. Configuration in the tsconfig.json file in the root directory

//配置 @
"baseUrl": ".",
"paths": {
    
    
	"@/*": ["src/*"]
}

Insert image description here

3. Usage examples

Insert image description here

おすすめ

転載: blog.csdn.net/qq_61402485/article/details/131619797
おすすめ