question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create modular build of jsPDF

See original GitHub issue

Right now nearly all jsPDF plugins and polyfills are packaged together with the main build, resulting in the minified bundle being ~300KB in size and growing.

Developers should choose which plugins and polyfills they want, instead of jsPDF choosing for them. I only use images, text, and pages, and only need FileSaver as a polyfill. The rest of the functionality is entirely unnecessary to me and unnecessarily uses up the network bandwidth and CPU when a user’s browser downloads + parses the giant file (not to mention it’s just one of many other dependencies in a project). There’s no need for me to have to install and package up all of html2canvas and downloadify when I don’t even use them. Or all of requirejs (which causes compatibility problems very easily), Blob.js, and the canvas implementation, if I don’t need them. etc. etc.

With a modular build I would do something like:

import jsPDF from 'jsPDF' // basic jsPDF functionality
import 'jsPDF-addImage' // add addImage functionality to jsPDF
import 'file-saver' // FileSaver polyfill

This would drastically reduce the size of the core jsPDF library, abstract out all the logic that is handled by plugins, make creating, updating, and managing plugins significantly easier, and entirely remove polyfills from the codebase. People would also be able to easily fork and create their own versions of existing plugins (like https://www.npmjs.com/package/jspdf-autotable)

As the plugins + polyfills are all in separate directories already and imported very similarly in https://github.com/MrRio/jsPDF/blob/master/main.js , this doesn’t seem like it would be altogether difficult to implement

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:20
  • Comments:22 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
sgelbcommented, Feb 1, 2017

I’d really appreciate some work in this direction. Can you comment on this idea, @MrRio?

5reactions
alex2wongcommented, Dec 21, 2018

Any update on modular build of jsPDF ? currently the jspdf.min.js are still over 300Kb. I know this refactor work would involve much work, not sure how long it would take to modernize the structure of core and plugins.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create modular build of jsPDF · Issue #839 - GitHub
With a modular build I would do something like: import jsPDF from 'jsPDF' // basic jsPDF functionality import 'jsPDF-addImage' // add ...
Read more >
Build a custom table with React/jsPDF | by Cory Harkins
Hello, and welcome to my blog tutorial on how to create a custom table and export it using jsPDF! This tutorial aims to...
Read more >
How to properly use jsPDF library - javascript - Stack Overflow
7 Answers 7 · Step 1: Add the following script to the header · Step 2: Add HTML script to execute jsPDF code...
Read more >
React.js jsPDF Project to Export Multiple Images to ... - YouTube
... of application here:https://webninjadeveloper.com/react/react-js- jspdf -project-to-export-multiple-images-to-pdf-document-in-browser-...
Read more >
jsPDF - Documentation - GitHub Pages
html . The fontconverter will create a js-file with the content of the provided ttf-file as base64 encoded string and additional code for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found