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

Consider building an ES6 Module as well #8

Closed
mattparrilla opened this issue May 10, 2017 · 2 comments
Closed

Consider building an ES6 Module as well #8

mattparrilla opened this issue May 10, 2017 · 2 comments

Comments

@mattparrilla
Copy link

mattparrilla commented May 10, 2017

Matt from Burlington, VT office here. Howdy team!

I've got a feature request: publish your package as an es6 module. I believe you can do this side by side with an es5 build (nwb does).

The reason: tree shaking. Webpack 2 offers tree shaking, but in order to take advantage of the feature, the module needs to be published as an ES6 module.

Obviously this is a huge package as it includes a ton of SVGs. It would be great if our users only had to pay the cost of the icons they were seeing.

I think all it might take is updating your .babelrc: https://medium.com/modus-create-front-end-development/webpack-2-tree-shaking-configuration-9f1de90f3233#b26a

Disclaimer: this is my first foray into webpack 2 and I don't know much about publishing modules. I just created a component library and was surprised that my library clocked in at >1MB and was further surprised to see that 450k of that comes from react-entypo.

BTW, I found this library organically, meaning Google, while looking for a way to get the new tracksuit icons in React. Was surprised to see you guys as the owners. Nice work!

@jasonhale
Copy link
Member

jasonhale commented May 11, 2017

Hi Matt!
I totally get the issue you're having. May I ask how you're importing the icons you need?
If you import the icons specifically they shouldn't take up so much space.
Like so:

import EntypoArrowBoldRight from 'react-entypo/lib/entypo/ArrowBoldRight';
import EntypoCalculator from 'react-entypo/lib/entypo/Calculator';

We recommend this approach as you're not importing all 411 icons... only the individual ones you need. I see our README examples aren't very good at explaining that and we can work on updating them to be more descriptive.

Does that help?

@mattparrilla
Copy link
Author

TL;DR: feel free to kill this issue! ES6 modules aren't all the way there yet and above solution works well enough

Though above solution works, I was still interested in experimenting with webpack tree shaking and so looked into getting a PR together that also built an ES6 module (basically transpile all code down into ES5, but use ES6 import/export instead of require). However upon investigating it looks like support for this sort of thing isn't official yet:
https://github.com/nodejs/node-eps/blob/4217dca299d89c8c18ac44c878b5fe9581974ef3/002-es6-modules.md#51-determining-if-source-is-an-es-module

and there are some recent reported issues with the not-yet-official approach:
infernojs/inferno#928

So, someday!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants