vite配置别名

我心飞翔 分类:vue

vite.config.ts

import { resolve } from "path";

export default defineConfig({
    resolve: {
        alias: {
            "@": resolve(__dirname, "./src"), //把 src 的别名设置为 @
        },
    },
});

解决 ts 中 使用"@" 的时候提示找不到模块的报错

import DateInput from "@/components/DateInput.vue";  (找不到模块“@/components/DateInput.vue”或其相应的类型声明。)

但是不影响使用。

tsconfig.json

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

回复

我来回复
  • 暂无回复内容