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的类型做检查
本文介绍了在使用Vite打包时遇到的vite.config.ts未被读取的问题,详细描述了问题的现象,包括@符号路径未被识别。通过分析定位到原因是类型检查工具vue-tsc的--noEmit选项导致配置未生效。解决方案是去掉该选项,使得Vite能够正确读取并执行vite.config.ts中的配置。

1425

被折叠的 条评论
为什么被折叠?



