当前位置:网站首页>Vite path alias @ configuration

Vite path alias @ configuration

2022-07-07 15:48:00 Sam young

vite.config.ts

Official configuration details
resolve.alias To configure

const path = require('path');
import {
     defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

// https://vitejs.dev/config/
export default defineConfig({
    
  plugins: [vue()],
  resolve: {
    
    //  Configure path alias 
    alias: {
    
      '@': path.resolve(__dirname, './src'),
    },
  },
});

tsconfig.json

paths and baseUrl

{
    
  "compilerOptions": {
    
    "experimentalDecorators": true,
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "strict": true,
    "jsx": "preserve",
    "sourceMap": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "lib": ["esnext", "dom"],
    "baseUrl": ".",
    "paths": {
    
      "@/*": [
        "src/*"
      ]
    },
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}

Just restart it and use it
 Insert picture description here

原网站

版权声明
本文为[Sam young]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130610294849.html