meteor

ES2015 modules (Import & Export)

Remarks#

MDN documentation for imports: https://developer.mozilla.org/en/docs/web/javascript/reference/statements/import MDN documentation for exports: https://developer.mozilla.org/en/docs/web/javascript/reference/statements/export ExploringJS chapter on modules: https://exploringjs.com/es6/ch_modules.html

Importing in app modules

Node modules

import url from 'url';
import moment from 'moment';

Meteor packages

import { Meteor } from 'meteor/meteor';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';

Importing in Meteor packages

In package.js:

Npm.depends({
  moment: "2.8.3"
});

In a package file:

import moment from 'moment';

Exporting variables from app modules

// Default export
export default {};

// Named export
export const SomeVariable = {};

Exporting symbols from Meteor packages

In your mainModule file:

export const SomeVar = {};

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow