From 68b9f4baa5def8348d862905044b1aa98a2d9f46 Mon Sep 17 00:00:00 2001 From: Przemek Wiech Date: Wed, 29 Apr 2020 22:29:25 +0200 Subject: [PATCH] lazy load jspdf to speed up page load --- src/chart.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/chart.tsx b/src/chart.tsx index 4779f60..cae23d9 100644 --- a/src/chart.tsx +++ b/src/chart.tsx @@ -1,5 +1,4 @@ import * as React from 'react'; -import jsPDF from 'jspdf'; import {event, select, Selection} from 'd3-selection'; import {interpolateNumber} from 'd3-interpolate'; import {intlShape} from 'react-intl'; @@ -395,8 +394,10 @@ export class Chart extends React.PureComponent { } async downloadPdf() { + // Lazy load jspdf. + const {default: jspdf} = await import('jspdf'); const canvas = await this.drawOnCanvas(); - const doc = new jsPDF({ + const doc = new jspdf({ orientation: canvas.width > canvas.height ? 'l' : 'p', unit: 'pt', format: [canvas.width, canvas.height],