feat: bundle module and use package exports #107
Closed
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-blob
v3 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-blob
anymore.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
cjs
andesm
versions of this module.For this, I introduced
esbuild
which 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-polyfill
makes 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-blob
innode-fetch
when providing the commonjs version of the package.What's included in this PR