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

ES modules exports #2718

Closed
mjeanroy opened this issue Dec 30, 2017 · 15 comments
Closed

ES modules exports #2718

mjeanroy opened this issue Dec 30, 2017 · 15 comments

Comments

@mjeanroy
Copy link

Hi,

Is there a plan to migrate to ES Modules in the future or do you consider it worthless? It would be great to be able to import individual methods using ES imports, allowing tree-shaking and many other build optimization.

I'm sorry if this question has already been asked, but I searched in issue and could not find anything about it. Thanks for all the work behind underscore!

@Kelichao
Copy link

Kelichao commented Mar 6, 2018

Feel it is not there yet

@unquietwiki
Copy link

I was able to add module exports { _ } to the end of my underscore.js file, to at least resolve the error message for importing as import _ from 'underscore.js'

@dreamalligator
Copy link

would be awesome 👍

@jashkenas
Copy link
Owner

Is there any good way we can add module exports to the main file, while maintaining backwards compatibility with non-module-supporting versions of JavaScript?

@unquietwiki
Copy link

unquietwiki commented Apr 23, 2018 via email

@dreamalligator
Copy link

maybe core-js is a good example, although probably too modular to directly follow https://github.com/zloirock/core-js

@mjeanroy
Copy link
Author

@jashkenas Thanks for your response.

I don't think that it is possible to add the import statements on top of the main file and maintaining backwards compatibility without any transpilation task.

The easiest solution, for me, would be to have a build task to translate import statements to UMD using babel and publish two versions of underscore: the first one with export and a second one for umd.

@lohfu
Copy link

lohfu commented Jan 17, 2020

@jashkenas what do you think of @mjeanroy's suggestion? i would be happy to help...

@jashkenas
Copy link
Owner

@jashkenas what do you think of @mjeanroy's suggestion? i would be happy to help...

Sure! I'd be happy to merge a PR that swaps to named exports for all of the Underscore functions, and also uses Rollup to publish a UMD version of the file.

@lohfu
Copy link

lohfu commented Jan 17, 2020

@jashkenas very cool! do you want to keep the src in one single file or can functions be placed in individual files?

@jashkenas
Copy link
Owner

One single file, please.

If we can keep the diff as small and the result as clean as possible, that would help greatly. Ideally, just adding named exports to the functions where they are — with Underscore itself as the default export.

@jgonggrijp
Copy link
Collaborator

@lohfu @mjeanroy has either of you worked on this in the meanwhile? Otherwise I'm offering to adopt this.

@lohfu
Copy link

lohfu commented Feb 22, 2020

@jgonggrijp unfortunately i have found no time to focus on this, so you are more than welcome to give it a go. if i find time in the near future to help out i will ping you and see how it is going. good luck, have fun!

@gogo765795
Copy link

Duplicate of #

jgonggrijp added a commit that referenced this issue Mar 29, 2020
ES modules exports (implements #2718)
@jgonggrijp
Copy link
Collaborator

Closed in #2826.

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

8 participants