当前位置:网站首页>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
}
}
}
边栏推荐
- Optimization of lazyagg query rewriting in parsing data warehouse
- Introduction to mongodb chapter 01 introduction to mongodb
- QT display ffmpeg decoded pictures
- Heavyweight live | bizdevops: the way to break the technology situation under the tide of digital transformation
- QT mouse tracking
- Shenzhen mintai'an intelligent second side_ The first offer of autumn recruitment
- 剑指 Offer II 032. 有效的变位词
- On the simple realization of Sanzi chess game and the method of judging the victory of n-zi chess
- Summer Ending
- On the realization of guessing numbers game
猜你喜欢

關於一道教材題的講解

Storage related contents of data in memory

《MongoDB入门教程》第01篇 MongoDB简介

Online service emergency research methodology

Explication d'un problème de manuel

Sword finger offer day 2 linked list (simple)

剑指 Offer II 032. 有效的变位词
Module 5 (microblog comments)

WIN10环境下配置pytorch

leetcode - 384. Scramble array
随机推荐
Sword finger offer II 029 Sorted circular linked list
C# 切换中英文输入法
LeetCode链表题解技巧归纳总结
剑指 Offer II 029. 排序的循环链表
Which Chinese virtual human is better? Sullivan, IDC: Xiaobing Baidu Shangtang ranks in the first echelon
Analyse de l'optimisation de la réécriture des requêtes lazyagg de l'entrepôt
解析数仓lazyagg查询重写优化
剑指 Offer II 032. 有效的变位词
Koa frame
关于扫雷的简易实现
Regular match the phone number and replace the fourth to seventh digits of the phone number with****
Intercept based on byte length
[pit avoidance refers to "difficult"] antd cascader implements new customized functions
Nova组件源码分析之冷迁移与Resize
提高排名的 15 个基本 SEO 技巧
Configuring pytorch in win10 environment
Module 5 (microblog comments)
And console Log say goodbye
Capabilities required by architects
Fedora 35 部署DNS主从和分离解析 —— 筑梦之路