Underscore: ES modules exports

Created on 30 Dec 2017  ·  15Comments  ·  Source: jashkenas/underscore

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!

enhancement

Most helpful comment

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.

All 15 comments

Feel it is not there yet

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'

would be awesome :+1:

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?

However Babel does it?

On Mon, Apr 23, 2018, 1:02 PM Jeremy Ashkenas notifications@github.com
wrote:

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?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/jashkenas/underscore/issues/2718#issuecomment-383704124,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA9fvx9tIUVYAxL0PqcGIoDwhLe25ulOks5trjNlgaJpZM4RPowg
.

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

@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.

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

@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.

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

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.

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

@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!

Duplicate of #

Closed in #2826.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xiaoliwang picture xiaoliwang  ·  3Comments

ksullivan picture ksullivan  ·  9Comments

umarfarooq125 picture umarfarooq125  ·  8Comments

zackschuster picture zackschuster  ·  5Comments

afranioce picture afranioce  ·  8Comments