Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js: support ES6 modules #12

Open
dominicbarnes opened this issue Jul 1, 2017 · 1 comment
Open

js: support ES6 modules #12

dominicbarnes opened this issue Jul 1, 2017 · 1 comment

Comments

@dominicbarnes
Copy link
Member

From @dominicbarnes on November 28, 2016 7:38

The more time goes on, the more I'd like to investigate using ES6 modules, rather than CommonJS. This would drastically affect the internals of this plugin, but ultimately it is the right direction to go in the long run.

I was previously thinking that I'd implement #17 by analyzing the CommonJS outputs, but kept running into blockers due to it's less-than-static nature. I recently discovered that rollup/webpack only perform tree-shaking on ES6 modules, since they are static by definition. (this drastically reduces the complexity)

All in all, I'm not sure what the right approach here is. The general use-case has been relying on code published to npm, which is generally pre-compiled to CommonJS. I also don't want to become too opinionated by bundling babel directly here to support the ES6/CommonJS divide.

It looks like rollup relies on jsnext:main in a package.json to reference a file that uses import and export, but I'm worried about an already fractured build process that uses npm code that assumes ES6 because of node 4+. But maybe I can piggy-back on the efforts of rollup and others.

Copied from original issue: makojs/js#99

@dominicbarnes
Copy link
Member Author

From @darsain on November 28, 2016 14:16

Apart of removal of unused code, the other awesome thing that these tools do is inline all module definitions. Or in other words, instead of mocking require() module system in the build, they inline the exported stuff, and thus remove the commonjs module system tax, which speeds up load times considerably.

So I'd be pretty excited to have this in mako as well :) But personally I'm unfamiliar how that works in practice in combination with existing stuff in npm, since I haven't really used rollup or webpack yet.

Also, I'm not aware that there is already a consensus on how are ES modules going to work in node. I know there has been a ton of going back and forth between people who want to make it seamless, with those that want a custom extensions like .mjs, and other horrible solutions. I'm afraid this might lead to some clashes later on, but can't give any specifics. Haven't kept up with it 😢.

@dominicbarnes dominicbarnes changed the title Switch to ES6 modules js: support ES6 modules Jul 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant