当我在 Vite 中使用 Vue 单文件组件时,我可以使用tsconfig.json 中的 baseUrl和路径别名将*.ts 文件导入到组件文件中。但是,这同样不适用于 *.vue 文件的导入,因为我遇到了运行时错误。
// ts files: works fine
import { FooModel } from "@/models/FooModel"
// vue files: relative path works fine
import { FooComponent } from "./models/FooComponent.vue"
// vue files: path alias gives a run-time error!
import { FooComponent } from "@/models/FooComponent.vue"
Vite.js Discord Server上有一个类似的问题,但尚未得到解答。
因此,我的主要问题是:如何让路径别名适用于 Vite 中的单个文件组件导入?
子问题是谁在 Vite 中解析 *.vue 文件的路径?使用 Vue CLI,这是在 webpack 中处理的,如果我没记错的话,那么在 Vite 中它是汇总?