Open sebastian-onlea opened 1 year ago
Hey @sebastian-onlea You are true. Could you submit PR?
I would like to merge your modifications if you can confirm that it works correctly in Node and browser environment.
Thanks! I'll follow the recommended testing steps in DEVELOPMENT.md
and run the tests; are there any other validation cases that I should check for both Node and browser coverage?
@sebastian-onlea Thank you...!!!
are there any other validation cases that I should check for both Node and browser coverage?
It's enough Node and browser! I'll support you after PR, I also check your code changes and bug check.
It would be nice to have a PR to be able to try your proposal and provide some feedback/help.
Currently I see 3 branches in your fork: https://github.com/sebastian-onlea/pdfme/branches ... with a pull request the correct branch would be clear.
Is your feature request related to a problem? Please describe.
tl;dr: static inclusion of
bwip-js
,@pdf-lib/fontkit
, and default Helvetica font data increases bundle size significantly, even when they're not being used.I've been using
@pdfme/generator
to embed PDF document/certificate creation features in e-learning module packages and it's been super—the WYSIWIG template designer is magical! The 2420kB webpack bundle is quite heavyweight, though, and profiling the bundle shows some hot potatoes:bwip-js
,fontkit
, andconstants.ts
. See "Additional context" for the bundle profile treemap.Describe the solution you'd like
bwip-js
can be async-imported when needed rather than statically importedpdfme
default Helvetica) can be embedded usingpdf-lib
'sembedStandardFont()
without the use offontkit
fontkit
on-demand when custom fonts are usedpdf-lib
'sembedStandardFont()
uses compressed font data from@pdf-lib/standard-fonts
, soHELVETICA
can be omitted frompdfme
'sconstants.ts
for an additional reduction in bundle sizeMy proof-of-concept implementation is in sebastian-onlea/pdfme:dev/optimize-bundlesize. The way I shoehorned
| { standardFont: '...' }
into theFont
definition isn't especially elegant, so I'm happy to take suggestions on that (or anything else in the patch!) before creating the PR.Describe alternatives you've considered
I've been working on optimizing the bundle size by working on a local fork; initially I was looking at cutting the extra libraries out entirely for our use cases, but async loading appears to work well enough while retaining opt-in support for other projects using custom fonts and barcode generation.
Additional context
.