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

🔥 Provide esm version #214

Closed
apertureless opened this issue Feb 15, 2018 · 4 comments
Closed

🔥 Provide esm version #214

apertureless opened this issue Feb 15, 2018 · 4 comments

Comments

@apertureless
Copy link

🙏 Feature Request

Hey, thanks a lot for this lib.

However I think it would be really awesome, if you could provide an esm build, too.
The reason is quite simple. Your source looks very clean and modern. And is using import and export. So imo this makes it perfect for tree shaking.

🕔 Current State

Right now if I am importing

import { LocalTime } from 'js-joda'

the whole js-joda lib will end up in my bundle. Because tree shaking is not working.
This is because you're providing only a umd build. Which is awesome if you're using it in the browser. However tree shaking is not working in this build.

💉 Fix

Should be quite simple to add a rollup config to output an ES module and in package.json just add the target in the module and jsnext:main field

 
"module": "dist/js-joda.esm.js",
 "jsnext:main": "dist/js-joda.esm.js",

This way modern bundlers like rollup and webpack 2+ will pickup the esm and be able to tree shake and older bundlers webpack 1, gulp or browser will pickup the umd version.

@pithu
Copy link
Member

pithu commented Feb 23, 2018

Hi @apertureless thanks for reporting and for using js-joda.

I absolutely agree, it would be great to have es module section. I pushed a first draft on a branch js-joda/js-joda/esm-experimental

Unfortunately the code in that branch with the es module breaks the webpack 3 build of a project depending on js-joda with a strange error message.

So we still have to investigate in this issue, if you find some obvious problem in the branch please let us know.

@pithu
Copy link
Member

pithu commented Mar 1, 2018

Short update:
I released version js-joda@v1.7.0 with an esm module build with rollup, but oversee that we still need to transpile some fancy things, like arrow functions, classes, etc. in the esm build.
So there is still some work todo, help is always welcome.
Until than i simply removed the pkg.module prop again (Release @v1.7.1).

@apertureless
Copy link
Author

Cool. Sorry for the late reply. Somehow did not get a notification.
I will take a look at the rollup file. I think babel is missing there.

I will provide a PR later. ✋

@pithu
Copy link
Member

pithu commented Mar 22, 2018

Finally its there. js-joda has now a pkg.module section with an esm build.

Beside your PR there where some more things to fix: like a node style module.exports in the code and a special babel config for the node test runner.

I took the opportunity and switched also all other builds to rollup. Just the karma tests are still running with webpack and waiting for migration.

Thx a lot for your hints again. I will close the issue. Please feel free to reopen it again, if there are some issues left.

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