[vite] not read vite.config.ts when build 编译时没有读取vite.config.ts文件

[vite] not read vite.config.ts when build 编译时没有读取vite.config.ts文件

enviroment

vite
vue
ts

problem

开发完打包资源,
执行 npm run build

报错:

Cannot find module '@/store/vuex' or its corresponding type declarations.
import { State } from "@/store/vuex";

location

将@符号路径改为 ../../store/vuex没有报错。

而实际在vite.config.ts文件中
配置过@符号的alias

  resole: {
    alias: {
      '@': path.join(__dirname, 'src')
    }
  }

为什么还是不认识@符号呢?

尝试在vite.config.ts文件中加入一行log

console.log(`vite.config.ts...`)

再次执行 npm run build
发现log内容没有打印出来

所以原因应该是:当前配置并没有被读取,也木有被执行

solution

默认build命令
"build": "vue-tsc --noEmit && vite build",

尝试指定配置文件,依然没有效果
"build1": "vue-tsc --noEmit && vite build --config vite.config.ts",

尝试去掉 vue-tsc --noEmit,解决问题,log有打印出来,@符号能被认识
"build": "vite build",

reason

noEmit
Vite 仅执行 .ts 文件的转译工作,并不执行任何类型检查。
vue-tsc --noEmit 打开类型检查,对 *.vue 文件和ts的类型做检查

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章