Build as ES module as well as CommonJS #120
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I can see this project is in active development, but I thought this PR may be useful to you, even just as a proof of concept.
In the Mastodon project we are currently integrating
emoji-mart
, but we'd like to avoid the situation where we need to load the entire module (921kB) for all users. We useemojiIndex
extensively, but the picker itself is only needed on-demand. So in principle, ifemoji-mart
were distributed as an ES module (with"module"
declared inpackage.json
), then we'd be able to do:...and Webpack tree-shaking would take care of the rest.
I'm not sure if the current master is a good representation of what you intend to ship in
dist
(e.g. with raw.svg
files?), but if so then this PR would be a reasonable approach to build both CommonJS and ES modules. Essentially it builds adist/cjs
directory (referenced by"main"
inpackage.json
) and then also adist/es
directory (referenced by"module"
inpackagejson
). Webpack 2+ should pick up on the"module"
version and thus allow for tree-shaking.