bpampuch / pdfmake

Client/server side PDF printing in pure JavaScript
http://pdfmake.org
Other
11.7k stars 2.04k forks source link

code splitting #2472

Open terragady opened 2 years ago

terragady commented 2 years ago

Hi, I am using react v18 and I am trying to code split pdfmake module but no luck. I have tried to use Lazy load from react in the component I am importing pdfmake but it is still in main js, tried async import of pdfmake but also it stays in main.js. I am only using pdfmake in specific occasion but it increases my bundle size by 75%. Is it possible to somehow load it only when needed?

rads92stx commented 2 years ago

Up - have the same problem

boldurean commented 1 year ago

Hi, I am using react v18 and I am trying to code split pdfmake module but no luck. I have tried to use Lazy load from react in the component I am importing pdfmake but it is still in main js, tried async import of pdfmake but also it stays in main.js. I am only using pdfmake in specific occasion but it increases my bundle size by 75%. Is it possible to somehow load it only when needed?

Why are you not use pdf make inside the worker? Load it dynamically with the component itself. have your worker file beside the component and just create new instance when you need.

const worker = useMemo(() => new Worker(new URL('./worker.js', import.meta.url)), []); // your code interacting with worker