当前位置:网站首页>vite在项目中配置路径别名
vite在项目中配置路径别名
2022-07-28 12:46:00 【影风莫】
vite 加 vue3项目中报错Cannot find module 'XXXXXX ’ or its corresponding type declarations
我们只需要在以下几个文件里面配置:
vite.config.ts:
注意这里用了node的path模块需要执行npm i --save-dev @types/node命令
import {
defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
const path = require('path');
export default defineConfig({
plugins: [vue()],
define: {
'process.env': {
},
},
resolve: {
// 配置路径别名
alias: {
'@': path.resolve(__dirname, './src'),
},
},
});
tsconfig.json:
配置baseUrl,paths
{
"compilerOptions": {
"target": "esnext",
"useDefineForClassFields": true,
"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"]
}
大工告成啦!接下来可以用@别名代表src的绝对路径
边栏推荐
- P1797重型运输 题解
- 今日睡眠质量记录75分
- 国产口服新冠药阿兹夫定安全吗?专家权威解读
- [apue] 文件中的空洞
- I miss the year of "losing" Li Ziqi
- Operator3-设计一个operator
- Merge table rows - three levels of for loop traversal data
- Tutorial on the principle and application of database system (061) -- MySQL exercise: operation questions 21-31 (V)
- 朋友发来几个面试题
- Shell basic concepts and variables
猜你喜欢

比XShell更好用、更现代的终端工具!

基于神经网络的帧内预测和变换核选择

org.apache.ibatis.exceptions.TooManyResultsException的异常排查过程

持续(集成-->交付-->部署)

《如何打一场数据挖掘赛事》入门版

30天刷题训练(一)

产品经理:岗位职责表

word打字时后面的字会消失是什么原因?如何解决?

After finishing, help autumn move, I wish you call it an offer harvester

Three men "running away" from high positions in the mobile phone factory
随机推荐
Jenkins--持续集成服务器
C language: optimized merge sort
Better and more modern terminal tools than xshell!
Org.apache.ibatis.exceptions.toomanyresultsexception
Denial of service DDoS Attacks
二舅能治好年轻人的精神内耗吗?
30天刷题计划(三)
合并表格行---三层for循环遍历数据
Beyond istio OSS -- current situation and future of istio Service Grid
I'm bald! Who should I choose for unique index or general index?
Blue Bridge Training (additional interview questions) day 7
C language: merge sort
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的边框颜色
Intra prediction and transform kernel selection based on Neural Network
[dark horse morning post] byte valuation has shrunk to $270billion; "Second uncle" video author responded to plagiarism; Renzeping said that the abolition of the pre-sale system of commercial housing
docker部署mysql 实现远程连接[通俗易懂]
火山石投资章苏阳:硬科技,下一个10年相对确定的答案
After finishing, help autumn move, I wish you call it an offer harvester
《如何打一场数据挖掘赛事》入门版
JWT login authentication + token automatic renewal scheme, well written!