Gradually upgrading to es6 modules


I’m looking into upgrading from 1.2 to 1.3. Our app consists of multiple packages, so we can go package-by-package. However, even a single package can be quite large. Too large to change it all at once.

Can we have a combination of the old-style (globals) with new-style (es6 modules) approach within one package?

As a quick experiment I tried just changing one file (wherein a collection was defined) by:
-Moving it out of the package.js definition
-Inside the file, instead of binding to our global namespace which is exported using api.exports, I export it using the es6 module syntax
-Everywhere I used the global, I now use an es6-style import.

The import statement seems to get translated to ‘require’ statements in the build process and I get this error:
ReferenceError: require is not defined

Am I doing something wrong or is this not possible?

Did you add api.use('ecmascript') ? -

I use angular-meteor, so I can’t include ecmascript since we already get pbastowski:angular-babel by including angular. However pbastowski:angular-babel also implies the modules package.

Edit: nevermind, I had to upgrade pbastowski:angular-babel

api.use('modules') should work too

Yeah, thanks, this made me realize I had to upgrade pbastowski:angular-babel.

After solving some remaining bugs I’ve got it to work. The possibility for a gradual upgrade is very, very nice!

yeah you can. Stuff still eagerly loads and includes packages. If you start adding codes, add it to the imports/ folder which is not eagerly loaded, then import it.