如果模块导出为 node.js 导出模块,我们可以使用 systemjs 导入方法导入它 [英] If a module exported as node.js export module can we import it using systemjs import method
问题描述
在 node 项目中,我们使用 require 关键字导入一个模块,如果 d.ts 不可用,我们可以在 angular2 项目中使用 import {} from '' 导入相同的模块吗?例如我可以在我的 angular2 项目中使用这个库
In node project we import a module using require keyword, can we import same module using import {} from '' in angular2 project, provided that d.ts is not avaliable? For example can I use this library in my angular2 project
https://github.com/basarat/typescript-collections/issues/new
推荐答案
是的,你可以.但是你只需要使用 ES6 语法 import
/export
.
Yes, you can. But you have to use only the ES6 syntax import
/export
.
对于 Node.js,您可以使用模块格式 CommonJS 或 UMD 编译代码.
For Node.js, you can compile the code using modules format CommonJS or UMD.
Here is a tutorial on how to use TypeScript with SystemJS. SystemJS will load the TypeScript source code and not the compiled code. In order to use JavaScript modules that are installed by npm, use the option packageConfigPaths
:
packageConfigPaths: ['node_modules/*/package.json']
另请参阅 GitHub 上的此主题,了解 SystemJS 的其他选项配置.
See also this thread on GitHub for other options of the SystemJS configuration.
这篇关于如果模块导出为 node.js 导出模块,我们可以使用 systemjs 导入方法导入它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!