Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bundle module and use package exports #107

Closed
wants to merge 1 commit into from

Conversation

SomaticIT
Copy link

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 and esm 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 in node-fetch when providing the commonjs version of the package.

What's included in this PR

  • use esbuild to bundle module in esm and cjs format
  • bundle dependencies to reduce module size
  • use package exports to automatically select the apropriate version
  • add build step to prepublishOnly
  • add build step to ci

- 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
@LinusU
Copy link
Member

LinusU commented Jul 29, 2021

Thanks for taking the time to investigate and submit a PR. I'm against this approach for the reasons given here:

node-fetch/node-fetch#1227 (comment)

@jimmywarting
Copy link
Contributor

jimmywarting commented Aug 13, 2021

Locking b/c it's nicer to keep the discussion in one place.
(We still keep a open mind and looking for a solution - it dose not mean we will overlook this PR)

Feel free to keep pushing commits and discussion in node-fetch/node-fetch#1227 where most of the discussion is already happening

@node-fetch node-fetch locked and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants