当前位置:网站首页>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
}
}
}
边栏推荐
- Storage related contents of data in memory
- Openstack -- creating virtual machines for Nova source code analysis
- AGCO AI frontier promotion (6.25)
- Include what you use to save chaotic header files
- 《MongoDB入门教程》第01篇 MongoDB简介
- 提高排名的 15 个基本 SEO 技巧
- KVM 脚本管理 —— 筑梦之路
- 买基金在哪里开户安全?还请赐教
- 关于扫雷的简易实现
- Used in time filter (EL table)
猜你喜欢

J2EE from entry to earth 01 MySQL installation

About data storage in memory

leetcode:918. 环形子数组的最大和【逆向思维 + 最大子数组和】

字符串各操作函数与内存函数详解

剑指 Offer 第 1 天栈与队列(简单)

leetcode - 384. Scramble array

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

On the realization of guessing numbers game

Solution to Nacos' failure to modify the configuration file mysql8.0
![[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
随机推荐
Golang keyboard input statement scanln scanf code example
關於數據在內存中的存儲下
[machine learning] parameter learning and gradient descent
剑指 Offer 第 1 天栈与队列(简单)
Explanation of a textbook question
Openstack -- creating virtual machines for Nova source code analysis
[pit avoidance means "difficult"] to realize editable drag and drop sorting of protable
重磅直播|BizDevOps:数字化转型浪潮下的技术破局之路
剑指 Offer 04. 二维数组中的查找
[pit avoidance refers to "difficult"] antd cascader implements new customized functions
KDD 2022 | GraphMAE:自监督掩码图自编码器
QT mouse tracking
揭秘GaussDB(for Redis):全面对比Codis
Used in time filter (EL table)
Summer Ending
关于一道教材题的讲解
Some knowledge of the initial C language
时间过滤器(el-table)中使用
The starting point for learning programming.
Alibaba stability fault emergency handling process