feat: bundle module and use package exports#107
Closed
SomaticIT wants to merge 1 commit intonode-fetch:mainfrom
Closed
feat: bundle module and use package exports#107SomaticIT wants to merge 1 commit intonode-fetch:mainfrom
SomaticIT wants to merge 1 commit intonode-fetch:mainfrom
Conversation
- use esbuild to bundle module in esm and cjs format - bundle dependencies to reduce module size - use package exports to automatically select the appropriate version - add build step to prepublishOnly - add build step to ci
7f36fbe to
0fce437
Compare
4 tasks
Member
|
Thanks for taking the time to investigate and submit a PR. I'm against this approach for the reasons given here: |
5 tasks
Contributor
|
Locking b/c it's nicer to keep the discussion in one place. Feel free to keep pushing commits and discussion in node-fetch/node-fetch#1227 where most of the discussion is already happening |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As explained in node-fetch/node-fetch#1226, the fact that
fetch-blobv3 is now pure ESM causes multiple problems with existing codebases.In JavaScript codebases, we need to use the async
import()which can create a lot of changes.In TypeScript codebases (with cjs module mode), it is impossible to use
fetch-blobanymore.I think that ESM is the future but it is not as stable as we think and it is not ready to be used everywhere.
The best way to ensure that all existing codebases can migrate to v3 is to provide both
cjsandesmversions of this module.For this, I introduced
esbuildwhich can transpile ESM to CJS and also can bundle the package.You can say: "node does not need packages to be bundled", which is true.
However, bundling is a good practice to reduce the module loading time, disk operations, memory footprint, etc.
It can also be used to bundle internal dependencies and so reduce the npm dependency tree (reduce install time, disk operations, memory footprint, npm hell, etc.).
Bundling
web-streams-polyfillmakes this module install size reduce from 6.5MB to 341kB.This PR is linked to node-fetch/node-fetch#1227. It allows to avoid bundling
fetch-blobinnode-fetchwhen providing the commonjs version of the package.What's included in this PR