Reputation: 167
I am using pdfmake in my angular 4 app and it really helps me in making nice pdf docs on the client side. But I am a little concerned when I look into the bundle-report after an aot build. It adds a considerable amount of weight to my chunk. Is there any way to reduce this, like importing only the needed parts/services/modules or so? Right now I am importing it as below
import { createPdf } from 'pdfmake/build/pdfmake';
Upvotes: 7
Views: 3225
Reputation: 51
Any way to reduce the bundle size of pdfmake?
Not directly, but you may defer the bundle loading from app initialization to the time you actually use pdfMake. This way you make a trade off - your 'main.js' file will be substantially smaller and therefore initial page load will be faster, but the first PDF generation operation will become slower due to the need of loading the module beforehand.
Here's how I did it with Promises (procedure sequence when you need to generate a PDF):
import('pdfmake/build/pdfmake').then(pdfMake => //generation code)
Upvotes: 1
Reputation: 1057
Try using this
import { createPdf } from 'pdfmake/build/pdfmake.min';
Import from min
Got this from github issue pdfmake/issues/1181
Upvotes: 3