当前位置:网站首页>How to configure aliases for typescript + vite projects
How to configure aliases for typescript + vite projects
2022-06-25 13:21:00 【acgCode】
In order to omit the long path , I often like to configure path aliases . But in typescript There will be some pits , For example, the import path cannot be in the form of “.ts” End of extension , Path not recognized, etc . Below I record my handling method .
vite.config.js:
export default defineConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, 'src') // Configure aliases
}
}
})
After configuration , You can go to ide The alias is used in . But this time I found , An error is reported under the path ,hover The error prompted after going up is : The import path cannot be in “.ts” End of extension .
Since extensions are not allowed , Then I'll omit the extension .
export default defineConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, 'src')
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json']
}
})
such , The extension does not need to be written .
however , The project cannot run , Error indication : Can't find this file .
There is a problem with the compilation , So I adjusted tsconfig.json, Add the following configuration :
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"] // Relative position requires configuration baseUrl To recognize , Otherwise, an error will be reported
}
}
}
边栏推荐
- And console Log say goodbye
- 与生产环境中的 console.log 说再见
- [machine learning] parameter learning and gradient descent
- . NET in China - What's New in . NET
- À propos du stockage des données en mémoire
- Openstack learning notes -grace component insight
- OpenStack学习笔记(二)
- 买基金在哪里开户安全?还请赐教
- [machine learning] model and cost function
- An article clearly explains MySQL's clustering / Federation / coverage index, back to table, and index push down
猜你喜欢

New Gospel of drug design: Tencent, together with China University of science and technology and Zhejiang University, developed an adaptive graph learning method to predict molecular interactions and

關於一道教材題的講解

AGCO AI frontier promotion (6.25)

Conway's law can not be flexibly applied as an architect?

关于一个图书小系统的实现

Three lines of code to simply modify the project code of the jar package

數據在內存中的存儲相關內容

数据在内存中的存储相关内容

Uncover gaussdb (for redis): comprehensive comparison of CODIS

Storage related contents of data in memory
随机推荐
Openstack learning notes -grace component insight
Regular match the phone number and replace the fourth to seventh digits of the phone number with****
关于扫雷的简易实现
Module 5 (microblog comments)
Conway's law can not be flexibly applied as an architect?
Judge whether it is a mobile terminal
Implementation of a small book system
药物设计新福音:腾讯联合中科大、浙大开发自适应图学习方法,预测分子相互作用及分子性质
字节跳动Dev Better技术沙龙来啦!参与活动赢好礼,限时免费报名中!
Confusion caused by the ramp
Maui的学习之路(二)--设置
重磅直播|BizDevOps:数字化转型浪潮下的技术破局之路
Stockage des données en mémoire
与生产环境中的 console.log 说再见
剑指Offer 第 2 天链表(简单)
[pit avoidance refers to "difficult"] halfcheckedkeys rendering problem in semi selected status of antd tree
学习编程的起点。
坡道带来的困惑
Heavyweight live | bizdevops: the way to break the technology situation under the tide of digital transformation
KVM script management - the road to dream