-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Using ESM for js-ipfs and js-libp2p codebases #951
Comments
🎉 🎉 🎉 🎉 |
Its great to see this - as its crazy that in JS you end up adding a MB or so to a file each time you use one function from another package as the tree expands. I'm trying to get my head around std/esm ! Currently I have modules that can be loaded in either node directly, or browserify can include them into a single file that can be loaded by a browser, the main difference is a "browser.js" file and a couple of places where the code has to check whether its running in the browser or node. I'm unclear how that change would work with std/esm, will browserify still gather all the requirements, or should some other tool do it ? |
Any thoughts on this . would using ESM make it hard to have javascript that can be used in both node & browserify (or equivalent) |
Not at all, @mitra42. John Dalton does a great job of explaining it on his post, make sure to check it out. |
Yes - I'd read that post before asking. It refers to switching format to .mjs and changing the import format to: |
The If we would change our code base to use ES Modules with an interop Consequencesfor Node.js usersIf we use
for Browserify users
for Webpack@3 users
|
@diasdavid what do you want to see/do before moving forward with this? |
Assuming package.json's |
Also worth having a close look at rollup, as it does NOT wrap each module in a function (maybe webpack3 stopped doing that too). those articles where written before Node.js decided on .mjs
lodash, three.js, react, d3, angular (afaik) use rollup for bundling their libraries. |
src/index.js would not be generated, it would be a wrapper for node.js using std/esm while generated files would still go into dist |
and re package.json fields we would probably do
|
re scope hoisting, webpack3 can do that but only if you use es modules all the way, same as rollup |
Hey, it would be great to have an ES modules version that can be imported directly into the browser with minimal tooling. I would like to use scripts of type module from unpkg or just import the files myself using import map-like tools to resolve bare imports. |
Allows users to access these additional types and utilities without having to create an instance of the client first. resolves ipfs#902 BREAKING CHANGE: `ipfs.util.isIPFS` has moved to a static export and should be accessed via `const { isIPFS } = require('ipfs-http-client')`. The modules available under `ipfs.types.*` have also become static exports. `ipfs.util.crypto` has been removed as it is not a dependency of `ipfs-http-client` so reduces the bundle size. If you need to use libp2p crypto primitives then please see the [js-libp2p-crypto](https://github.com/libp2p/js-libp2p-crypto) project for info on how to use it in your project. Finally `ipfs.util.getEndpointConfig` is now a direct instance method, `ipfs.getEndpointConfig` License: MIT Signed-off-by: Alan Shaw <[email protected]>
FYI: there's a little discussion on the skypack.dev github issues about the problems supporting ipfs on skypack: |
All the newest multiformats and ipld JS libraries are native ESM now. We had to write some build tooling to make them work nice but we’re pretty happy with it all now. However, migrating to this will change the required versions of Node.js to those that are aware of package.json exports so I’m no sure this is a change js-ipfs is ready to make. |
@mikeal nodejs v10 LTS end-of-life is coming up on 2021-04-30, so I think it's time to revisit this decision. https://nodejs.org/en/about/releases/ https://nodejs.org/api/packages.html#packages_exports (see the "History") |
I would also like to add that by moving to ESM it would make it far easier for someone to make a fork that is compatible with Deno / Browser without having to preform significant modifications. |
js-ipfs is being deprecated in favor of Helia. You can #4336 and read the migration guide. js-IPFS switched to ESM in version |
I read yesterday John Dalton's announcement on
std/esm
-- https://medium.com/web-on-the-edge/es-modules-in-node-today-32cff914e4b --. tl;dr; it enables the usage of ESM without having to add transpilation steps and with little to no overhead.I'm exciting for this announcement as it speeds up the adoption of ESM which otherwise we would have for April 2018 to have a LTS version with unflagged support or to 2020 until every LTS version of Node.js has full support.
ESM offer better treeshaking for browser bundles -- https://webpack.js.org/guides/tree-shaking/ -- as it is capable of eliminating dead code, making our bundles way smaller which is one of the main feature requests by our users.
What are other thoughts?
The text was updated successfully, but these errors were encountered: