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

Add ES module build #138

Merged
merged 2 commits into from Jan 15, 2020
Merged

Add ES module build #138

merged 2 commits into from Jan 15, 2020

Conversation

blikblum
Copy link
Contributor

@blikblum blikblum commented Dec 14, 2019

Fixes #129

Adds an ES module build along side existing one.

Code wise there's no change. I tested in a webpack project and is working fine.

Anyway is a breaking change because webpack users that import bottle with require will break:

import Bottle from 'bottlejs'; // works fine as before

const Bottle = require('bottlejs'); // does not work

// would need to change to 

const Bottle = require('bottlejs').default;

This is far from ideal.

Solutions:

  1. Avoid default export and use an named export. Would be consumed as below being consistent for both ES and CJS consumers
// ES import
import { Bottle } from 'bottlejs'; 
// CJS require
const { Bottle } = require('bottlejs');
  1. Do not use module entry in package. The users by default would still use the UMD build (no Breaking Change) and to use es module version would need to be explicit:
// ES import
import Bottle from 'bottlejs/dist/bottle-es'; 

Personally i'm in favor of 1 since is a better solution long term but 2 is also doable.

Some context:

markedjs/marked#1571 (comment)
webpack/webpack#4742 (comment)

@young-steveo
Copy link
Owner

This is great! thanks. I'll review and test it soon.

@blikblum
Copy link
Contributor Author

blikblum commented Jan 7, 2020

Hi, any updates?

Anything i can do?

@young-steveo
Copy link
Owner

@blikblum Sorry, I've been on holiday for a long while.

If I understand your comments correctly, this works both before and after your change:

import Bottle from 'bottlejs';

and this works before your change but not after:

const Bottle = require('bottlejs');

I'm fine bumping the major version number of bottle and leaving this the way you've described (I may have some additional breaking changes to make anyway). Let me know if I understand that correctly (I don't use webpack.)

@blikblum
Copy link
Contributor Author

If I understand your comments correctly,

Yes you are right

To use require would need to be:

const Bottle = require('bottlejs').default;

@young-steveo young-steveo merged commit 0895360 into young-steveo:master Jan 15, 2020
@blikblum
Copy link
Contributor Author

blikblum commented Aug 6, 2020

Hi, any news when a new release will be done, with ES modules support?

ES modules are required for tools like vite, pika and es-dev server

Let me know if i can help somehow

@young-steveo
Copy link
Owner

@blikblum
Copy link
Contributor Author

Many thanks

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

Successfully merging this pull request may close these issues.

Add ES module build
2 participants