Using ES6 import/exports in Meteor packages

I’m writing my own Meteor package, I would like to use ES6 import/exports from within the package to organize the package code, is this even possible? If it’s not, can someone direct me to some sample package projects with nice organization?

Yes it’s possible.

Check out the source for jagi:astronomy. It’s really well organized and uses ES2015 modules.

Thanks!

Quick question though, I assume import/export is only possible if

Package.onUse(function(api) {
  api.versionsFrom('1.3');

If I want to support users who are using Meteor versions less than 1.3, am I out of luck?

You could possibly support versions prior to 1.3, but you’ll likely need to maintain 2 separate sets of files (one with import/export statements, and one without) and then check for api.mainModule and use it to load the files that use modules, and if not then use api.addFiles to load the files for versions prior to 1.3. This of course sounds like a ton of work to me :slight_smile: