Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

src/index.js as main in package.json #46

Closed
such opened this issue Jan 23, 2018 · 8 comments
Closed

src/index.js as main in package.json #46

such opened this issue Jan 23, 2018 · 8 comments
Labels
kind/support A question or request for support status/deferred Conscious decision to pause or backlog

Comments

@such
Copy link

such commented Jan 23, 2018

Hey,

Thank you for this package!

I was just wondering if there is a reason why src/index.js is configured as the main file instead of dist/index.js?
It messes up with webpack that tries to minify src/index.js even though it's not ES5.

Thanks!

@such
Copy link
Author

such commented Jan 23, 2018

Actually, webpack does not like dist/index.js either. I guess it's because it contains the let keyword...

@such
Copy link
Author

such commented Jan 23, 2018

Apparently this is linked to ipfs/aegir#175. Not sure if you want to keep this issue opened...

@daviddias daviddias added the status/ready Ready to be worked label Jan 25, 2018
@daviddias
Copy link
Member

Strange that your report is that WebPack doesn't like let. Are you trying to use ES5 only code?

//cc @victorbjelkholm to help here.

@daviddias daviddias added kind/support A question or request for support status/deferred Conscious decision to pause or backlog and removed status/ready Ready to be worked labels Jan 25, 2018
@such
Copy link
Author

such commented Feb 15, 2018

@such
Copy link
Author

such commented Feb 15, 2018

By the way I have the same issue with https://github.com/libp2p/js-libp2p-crypto that's built with aegir as well, but switching the main from src/index.js to dist/index.js does the trick there.

My workaround is to use window.require instead of import for now...

@daviddias
Copy link
Member

dist/index.js is the bundle, that means that it has the code + all of its dependencies shimmed. We want to enable users to create their own bundle so that they can trim unused code and only shim dependencies once.

aegir also uses WebPack for the bundling and minifies it with uglify-es (https://github.com/ipfs/aegir/blob/master/package.json#L81) which supports ES6. You can check our WebPack config at https://github.com/ipfs/aegir/tree/master/src/config

@such
Copy link
Author

such commented Feb 15, 2018

I guess it's pretty hard to provide a library that can be used properly from Node and from the browser. I'm using create-react-app and I'd rather not run eject to be able to update the webpack config.
It makes a lot of sense that you want to enable users to create their own bundle. But it's not incompatible with transpiling to ES5 in a lib directory before publishing and pointing the main to lib/index.js. Sadly this seems to still be the current guideline for packages on npm.
But that's basically what's proposed in the issue I've linked before and I'd understand if you were not willing to go that way!
Thanks!

@hugomrdias
Copy link
Member

old issue gonna close this, feel free to reopen

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/support A question or request for support status/deferred Conscious decision to pause or backlog
Projects
None yet
Development

No branches or pull requests

3 participants