使用路径打字稿进口一些根 [英] Typescript import using path from some root
问题描述
有没有简单的方法来设置,以便我能导入
一些根本点开始?
Is there any simple way to set up so that I can import
starting from some root point?
例如:
- module1
\- file1.ts
- module2
\- file2.ts
在文件2,我想导入
文件1
in file2 i want to import
file1
import { foo } from '../module1/file1'
我希望做的却是这样的:
What I would like to do instead is something like:
import { foo } from 'src/module1/file1'
Angular2以某种方式使用这个(见的https://github.com/angular/angular/blob/master/modules/angular2/src/core/compiler/compiler.ts).我看着他们的构建过程,但它太复杂,我不知道他们是如何使这一点。
Angular2 somehow uses this (see https://github.com/angular/angular/blob/master/modules/angular2/src/core/compiler/compiler.ts). I looked into their build process, but it's so complex, I'm not sure how they enabled this.
推荐答案
https://开头www.npmjs.com/package/app-module-path 似乎是节点的最佳解决方案。
https://www.npmjs.com/package/app-module-path seems to be the best solution for node.
这篇关于使用路径打字稿进口一些根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!