使用路径打字稿进口一些根 [英] Typescript import using path from some root

查看:116
本文介绍了使用路径打字稿进口一些根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有简单的方法来设置,以便我能导入一些根本点开始?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆