Mark package as sideEffect free in package.json #1199
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.
Hi @Hopding!
I'm utilising this library in a slightly different way from most, I'm just using the low-level primitives available in
/core
and creating PDFs semi-manually. This library is amazingly flexible, and means I don't have to re-implement difficult things like image/font loading. Hurrah!However, despite using the ESM build (
pdf-lib/es/index.js
), many bundlers still bundle the entire library by default.As a simple example, the file below only has one
pdf-lib
import:Yet bundling with ESbuild...
esbuild --bundle ./in.js --minify --outfile=out.js
...gives an output size of
425.8kb
, which is the whole library!If
pdf-lib
declared itself as side-effect free, bundlers can be more aggressive with tree-shaking, and remove unused exports. I believe pdf-lib can do so, because all modules are self-contained and don't modify each other or global scope.The same test with this PR applied...
13.9kb
!For more info, here's Webpack's documentation on this setting:
https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free
Finally - thank you for your hard work on this library! 👌