-
-
Notifications
You must be signed in to change notification settings - Fork 5
Use multiple exports #38
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,59 @@ | ||
| import esbuild from 'rollup-plugin-esbuild'; | ||
| import dts from 'rollup-plugin-dts'; | ||
|
|
||
| // Make it explicit that we don't want to include external deps in bundle | ||
| // files. | ||
| const external = id => !/^[./]/.test(id); | ||
| // Make it explicit that we don't want to include external dependencies in | ||
| // bundle files. | ||
| const external = ['debug']; | ||
|
|
||
| export default [ | ||
| /** | ||
| * Create ES and CJS bundle files and their source map files. | ||
| * Create ES and CJS bundles of packets and utils and also source map | ||
| * files. | ||
| * | ||
| * NOTE: We also need to bundle utils/helpers.ts because it's used by | ||
| * packets and, if not specified, rollup will generate two helpers-xxx.js | ||
| * files, ES and CJS, both with .js extension, and will make Node believe | ||
| * that both are CJS due to their .js extension. | ||
| */ | ||
| { | ||
| input: 'src/index.ts', | ||
| plugins: [esbuild({ include: /\.ts$/ })], | ||
| input: { | ||
| packets: 'src/packets/public.ts', | ||
| utils: 'src/utils/public.ts', | ||
| 'utils/helpers': 'src/utils/helpers.ts', | ||
| }, | ||
| plugins: [esbuild()], | ||
| output: [ | ||
| { | ||
| format: 'es', | ||
| file: 'lib/rtp.js.bundle.mjs', | ||
| dir: 'lib', | ||
| entryFileNames: '[name].mjs', | ||
| sourcemap: true, | ||
| }, | ||
| { | ||
| format: 'cjs', | ||
| file: 'lib/rtp.js.bundle.cjs', | ||
| dir: 'lib', | ||
| entryFileNames: '[name].cjs', | ||
| sourcemap: true, | ||
| }, | ||
| ], | ||
| external: external, | ||
| }, | ||
| /** | ||
| * Create a .d.ts bundle file for TypeScript types. | ||
| * Create ES and CJS types bundles of packets and utils. | ||
| */ | ||
| { | ||
| input: 'src/index.ts', | ||
| plugins: [dts({ include: /\.ts$/ })], | ||
| output: { | ||
| format: 'es', | ||
| file: 'lib/rtp.js.bundle.d.ts', | ||
| input: { | ||
| packets: 'src/packets/public.ts', | ||
| utils: 'src/utils/public.ts', | ||
| }, | ||
| plugins: [dts()], | ||
| output: [ | ||
| { | ||
| format: 'es', | ||
| dir: 'lib', | ||
| entryFileNames: '[name].d.ts', | ||
| }, | ||
| ], | ||
| external: external, | ||
| }, | ||
| ]; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, I will comment based on the assumption that the purpose of splitting is to reduce the bundle size.
I think it’s a matter of preference, but I believe having a main that exports everything would be a good idea. Since consumers usually use a bundler, when using ESM, tree shaking will still be performed even without excessive splitting. Additionally, adding "sideEffects": false to package.json is expected to further improve tree shaking efficiency.
People who care about size are definitely using a bundler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't care about library size. This is intended to be a library for Node despite it works in browsers too. My goal is to provide a modern import mechanism instead of the classic index based single import which IMHO looks ancient.
With that in mind, I am not sure why I am doing bundling of packets and utils. Instead I would prefer to have 3 lib folders, lib-es, lib-cjs and types, and replicate in all those folders the whole file tree of src folder:
Then the exports in package.json would be similar to what I have done in this PR, so entry points would also be "rtp.js/packets" and "rtp.js/utils".
In summary, despite what I have done in this PR so far, I see no reason to bundle anything.
Does it make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I'm doing exactly that with babel directly and getting rid of rollup. Working on it.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I don’t think exporting individually is necessarily the modern approach.
Having multiple entry points for exports has specific advantages, and if none of these apply, there is no real benefit to splitting:
Additionally, even in a Node.js environment, keeping the size small can be beneficial, such as for AWS Lambda, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I am not focusing on tree shaking or lib size. My points are:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@satoren I'm doing all that in this new PR #39.