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

fix: Publish config uses ES dist file #429

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Chocobozzz
Copy link
Contributor

@Chocobozzz Chocobozzz commented Oct 29, 2024

Use ES dist file as default export so consumer don't have to rebuild all files

Especially useful for consumers to not polyfill node dependencies of bittorrent-tracker dependency

@mrlika
Copy link
Member

mrlika commented Oct 29, 2024

When publishing an npm package, the best practice is to export transpiled .js source files.

The package's consumers might have specific build processes or configurations. Providing the source files allows them to integrate a package seamlessly into their workflow regarding compatibility, flexibility, tree-shaking, etc.

For example, a node dependency polyfill may already be included in a codebase, and including it the second time makes the end application much bigger.

Can the bundled ES module be somehow exported as an alternative to the existing one? https://webpack.js.org/guides/package-exports/

@mrlika
Copy link
Member

mrlika commented Oct 29, 2024

Something like:

 "exports": {
    ".": "./lib/index.js",
    "./esm": "./dist/p2p-media-loader-core.es.js"
  }

But this approach will also require somehow binding types to the "./esm" export.

Use ES dist file as default export so consumer don't have to rebuild all
files

Especially useful for consumers to not polyfill node dependencies
of bittorrent-tracker dependency
@Chocobozzz
Copy link
Contributor Author

I understand your point. However front-end libraries tend to ship the ES dist file by default (shaka player, hls.js or video.js do this kind of thing). It's also the recommended solution chosen by Vite: https://vite.dev/guide/build#library-mode

I suggest to use the exports method so consumers have the choice to use the source file, while specifying the ES module by default:

  • Most devs don't want to spend time on mocking bittorrent-tracker server dependencies
  • Your build process is good enough to tree-shake what p2p-media-loader doesn't need (especially the bittorrent-tracker server)
  • Using a custom exports requires consumers to have specific tsconfig settings (moduleResolution/module options) that may not be compatible with their current setup
  • Some frameworks (like Angular) don't allow to easily change the build setup to choose the appropriate file
  • Devs that want build control should have enough knowledge to choose the appropriate exports

I updated the PR with my proposal.

@mrlika
Copy link
Member

mrlika commented Nov 3, 2024

Thanks, we will test the proposed approach and give our feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants