如果模块导出为 node.js 导出模块,我们可以使用 systemjs 导入方法导入它 [英] If a module exported as node.js export module can we import it using systemjs import method

查看:94
本文介绍了如果模块导出为 node.js 导出模块,我们可以使用 systemjs 导入方法导入它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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.

这是有关如何在 SystemJS 中使用 TypeScript 的教程.SystemJS 将加载 TypeScript 源代码而不是编译后的代码.为了使用由 npm 安装的 JavaScript 模块,请使用选项 packageConfigPaths:

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

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