当前位置:网站首页>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
}
}
}
边栏推荐
- Serevlt初识
- Detailed explanation of string operation functions and memory functions
- Module 5 (microblog comments)
- leetcode - 384. 打乱数组
- [machine learning] parameter learning and gradient descent
- There is a problem with the date when MySQL imports and exports data to excel
- 量化交易之回测篇 - 期货CTA策略策略(TQZFutureRenkoWaveStrategy)
- leetcode:456. 132 模式【单调栈】
- Configuring pytorch in win10 environment
- Alibaba stability fault emergency handling process
猜你喜欢

Related examples of data storage in memory

Stockage des données en mémoire

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

剑指 Offer II 032. 有效的变位词

药物设计新福音:腾讯联合中科大、浙大开发自适应图学习方法,预测分子相互作用及分子性质

leetcode - 384. 打乱数组
![[data visualization] antv L7 realizes map visualization, drilldownlayer drill asynchronously obtains data, and suspends the warning box](/img/81/f8280f16efa314d736c3a869c32ef0.jpg)
[data visualization] antv L7 realizes map visualization, drilldownlayer drill asynchronously obtains data, and suspends the warning box
![[flask tutorial] flask overview](/img/e8/d85ac54f3a9eb3b1ab31852761154c.jpg)
[flask tutorial] flask overview

Maui's learning path (II) -- setting

Koa frame
随机推荐
Qt鼠标跟踪
关于数据在内存中的存储下
JVM parameter interpretation
爱可可AI前沿推介(6.25)
剑指 Offer 04. 二维数组中的查找
剑指offer 第 3 天字符串(简单)
It's an artifact to launch a website in a few minutes
始终保持疫情防控不放松 营造安全稳定的社会环境
Sword finger offer II 028 Flatten multi-level bidirectional linked list
Always maintain epidemic prevention and control and create a safe and stable social environment
Back test of quantitative trading - example of futures CTA strategy (tqzfuturerenkoscalpingstrategy)
[pit avoidance refers to "difficult"] halfcheckedkeys rendering problem in semi selected status of antd tree
關於一道教材題的講解
Seven competencies required by architects
leetcode - 384. 打乱数组
剑指 Offer II 025. 链表中的两数相加
Using swiper to realize seamless rotation of multiple slides
Fedora 35 部署DNS主从和分离解析 —— 筑梦之路
[pit avoidance means "difficult"] antd select fuzzy search
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