惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
S
Securelist
P
Proofpoint News Feed
D
DataBreaches.Net
Cisco Talos Blog
Cisco Talos Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Project Zero
Project Zero
A
About on SuperTechFans
罗磊的独立博客
WordPress大学
WordPress大学
月光博客
月光博客
Latest news
Latest news
C
Cyber Attacks, Cyber Crime and Cyber Security
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Privacy International News Feed
AI
AI
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence
Help Net Security
Help Net Security
T
Tor Project blog
V
Vulnerabilities – Threatpost
C
Cisco Blogs
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
MyScale Blog
MyScale Blog
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
Forbes - Security
Forbes - Security
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
T
Threat Research - Cisco Blogs
B
Blog RSS Feed
博客园 - 叶小钗
N
News and Events Feed by Topic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Simon Willison's Weblog
Simon Willison's Weblog
C
CERT Recently Published Vulnerability Notes
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic

小小孩

vaultwarden 部署 - 小小孩 去除宝塔面板一些无用的页面信息 - 小小孩 如何在 Bing 和 百度搜索中去除 CSDN 搜索结果 Nginx 安装 brotli 模块 - 小小孩 JavaScript 高性能现代网页截图 - 小小孩 JS 深拷贝终结者 structuredClone - 小小孩 http 协议头 Content-Disposition 的作用 - 小小孩 Echarts示例 Demo 合集网站 - 小小孩 LNMP Nginx 安装 brotli 模块
前端项目路径别名终极解决方案 - 小小孩
小小孩 · 2001-11-11 · via 小小孩

原生路径解决

Node.js v12.19.0 开始,开发人员可以使用 Subpath Imports 在 npm 包中声明路径别名。这可以通过 package.json 文件中的 imports 字段来完成。不需要在 npm 上发布包。在任何目录中创建一个 package.json 文件就足够了。因此,这种方法也适用于私人项目。

配置路径别名,假如有项目结构如下:

my-project  
├── src/  
│ ├── components/  
│ │ └── searchForm/  
│ │ └── form/  
│ │ └── index.ts  
│ ├── pages/  
│ │ └── login/  
│ │ └── about/  
│ │ └── home/ 
│ └── mock/  
│ └── api/  
│ └── index.ts  
└── package.json

我们可以在 package.json 中这么配置:

{
 "name": "my-awesome-project",
 "imports": {
  "#*": "./*"
 }
}

接下来就是愉快的使用了:

import { SearchForm } from "#src/components/searchForm";