Meteor with Angular 2 - 如何使用 fs 等节点库?
Meteor with Angular 2 - how to use node libraries like fs and others?
全部!
基本问题:在之前的很多app中,我都是这样做的:
const fs = require('fs');
这也行不通...
var fs = Npm.require('fs');
现在...使用 angular 2 和 meteor 和 typescript 我不知道如何生成相同的代码行。
有什么解决办法吗?实际上我只需要从我的文件系统加载一个 json 文件,但将来我将需要使用许多其他库,如 S3 (amazon) 和其他库。
ty !
我假设您使用的是 Meteor 版本 1.3?如果是这样,请看一下this section of the Meteor guide. Meteor 1.3 uses ES2015 module syntax with the import
and export
keywords. You can learn more about this syntax here。
在你的情况下,你应该能够在你的 Meteor 应用程序中导入和使用 fs npm 包:
import fs from 'fs'
然后您可以通过该文件使用该变量。
当然,这是假设您首先通过 meteor npm install <package-name> --save
安装并保存了 npm 包到您的项目中
我不确定您以前是否使用过它,但是 this Angular2-Meteor 教程也应该派上用场。
全部!
基本问题:在之前的很多app中,我都是这样做的:
const fs = require('fs');
这也行不通...
var fs = Npm.require('fs');
现在...使用 angular 2 和 meteor 和 typescript 我不知道如何生成相同的代码行。
有什么解决办法吗?实际上我只需要从我的文件系统加载一个 json 文件,但将来我将需要使用许多其他库,如 S3 (amazon) 和其他库。
ty !
我假设您使用的是 Meteor 版本 1.3?如果是这样,请看一下this section of the Meteor guide. Meteor 1.3 uses ES2015 module syntax with the import
and export
keywords. You can learn more about this syntax here。
在你的情况下,你应该能够在你的 Meteor 应用程序中导入和使用 fs npm 包:
import fs from 'fs'
然后您可以通过该文件使用该变量。
当然,这是假设您首先通过 meteor npm install <package-name> --save
我不确定您以前是否使用过它,但是 this Angular2-Meteor 教程也应该派上用场。