-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
Conversation
24bc23b
to
66167f2
Compare
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/ |
Something like:
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
66167f2
to
d2880fc
Compare
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
I updated the PR with my proposal. |
Thanks, we will test the proposed approach and give our feedback |
I researched and didn't see that modern NPM packages that export ES modules do bundling. But bundling dependencies is even considered harmful. The NPM ecosystem expects packages to manage dependencies via package.json. This allows for better dependency resolution and version management and ensures that packages aren't included multiple times in the end application bundle. ChatGPT
https://www.reddit.com/r/typescript/comments/dsidr4/best_practices_for_organizingarchitecting_a_npm/
|
@Chocobozzz, we solved your issue using conditional exports. Could you verify the solution on your end? "exports": {
".": {
"p2pml:core-bundle": "./dist/p2p-media-loader-core.es.js",
"import": "./lib/index.js"
}
},
"types": "./lib/index.d.ts", A bundler or JS runtime should specify the Vite: export default defineConfig({
plugins: [
//nodePolyfills(),
react(),
],
resolve: {
conditions: ['p2pml:core-bundle'],
},
}); Node.js, webpack, Rollup: https://webpack.js.org/guides/package-exports/#conditions-custom |
Hi @Chocobozzz, do you have updates on the approach described in the comment above? If there are no issues, we want to include it in the new release. |
Hi and sorry for the late answer. Conditional export is interesting but unfortunately the angular framework doesn't allow us to add conditions. If we could use Vite directly in Angular I would not have raised this issue ^^ I consider this is a specific PeerTube use case and I don't expect you to fix it. I'll just create another NPM package of p2p-media-loader in |
@Chocobozzz, I may be wrong, but there is a way to override
angular.json
// webpack.partial.js
|
Angular is moving on esbuild, and we use this new builder in peertube: https://angular.dev/tools/cli/build But thanks, I discovered https://www.npmjs.com/package/@angular-builders/custom-esbuild#custom-esbuild-application. I'll try it |
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