Typescript模块导入configuration文件

我想要伪造一些configuration文件来访问node_modules的path。 看来做下面的事情是不可能的,那么我应该怎样锻造我的道路呢?

目标是写一些node_modules的绝对path(导致一些文件被拆分,所以这是需要的)。

import someFileSettings from "./../../models/someFileSettings"; import * as request from JSON.stringify(someFileSettings .somePathIneed+"request"); 

不,这是不可能的,因为TypeScript模块遵循标准的ES6模块。 为此,有一个基于promise的模块加载器API

以下是Axel Rauschmayer博士的解释:

16.9.1我可以使用variables来指定从哪个模块导入?

import语句是完全静态的:它的模块说明符总是固定的。 如果要dynamic确定要加载的模块,则需要使用编程式加载程序API :

 const moduleSpecifier = 'module_' + Math.random(); System.import(moduleSpecifier) .then(the_module => { // Use the_module }) 

…但是,注意这个警告:

模块加载器API不是ES6标准的一部分