スラッシュで始まらないローカル インポートと、同じモジュール内の node_modules からのインポートの両方を可能にする typescript モジュール解決戦略はありますか?
「moduleResolution」を「node」に設定すると、コンパイラはローカル モジュールを見つけることができません。他のすべてのオプションを使用すると、インポートしようとしている node_modules ディレクトリにモジュールが表示されません。
ファイルに次のインポートがあります。
import {Injectable} from "angular2/core";
import {Logger} from "core/logging/Logger";
「angular2/core」は node_modules にあり、「core/logging/Logger」は私のローカル モジュールです。
angularのコードを見ると、両方があるように見えます。http.ts モジュール: https://github.com/angular/angular/blob/master/modules/angular2/src/http/http.ts
import {Injectable} from 'angular2/core'; //this is local
import {Observable} from 'rxjs/Observable'; //this probably comes from node_modules
詳細な背景情報:
私は 2 つのサブプロジェクトで構成されるプロジェクトを持っています:
- ライブラリ
- アプリ
ライブラリは、アプリが使用するいくつかのユーティリティを定義します。私のビルド プロセスは、最初に「ライブラリ」サブプロジェクトをビルドし、それを (d.ts ファイルと一緒にコンパイルされた js) を「アプリの node_modules の「ライブラリ」サブフォルダにコピーしてから、「アプリ」をコンパイルします。
「ライブラリ」には、次のクラスがあります。
//file project/library/jsonparser/JSONParser.ts
class JSONParser {...}
//file project/library/services/ConfigurationService.ts
import {JSONParser} from "../jsonparser/JSONParser"
class ConfigurationService {
constructor(parser: JSONParser){ ... }
}
「アプリ」で:
import {JSONParser} from "library/jsonparser/JSONParser" //this comes from node_modules in 'app'
import {ConfigurationService} from "library/services/ConfigurationService" //from node_modules
class AppConfigurationService extends ConfigurationService {
constructor(parser: JSONParser) {
super(parser);
}
}
これは、JSONParser に非パブリック フィールドがあるとすぐにはコンパイルされません (これらは 2 つの異なる場所からインポートされるため、typescript の場合、これらは 2 つの異なる型になります)。そのため、最初にスラッシュを付けずにモジュールを 2 つインポートしようとしています。しかし、おそらくそれに対する他の解決策はありますか?