-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create modular build of jsPDF #839
Comments
Yeah this is an interesting problem. How do other libraries tackle it? |
There are several actionable steps
Further steps would involve automated testing and automated builds, such that a new version can be automatically released on NPM as soon as any change happens with very little hassle, among other steps. I can get started on this perhaps by next week, as there is noticeable lag my users currently see due to the load time increase by this library. It would have to be done as several PRs and as the current maintainer it's up to you how you want each of the plugin repositories to be created (under an umbrella organization or not) and who the maintainers should be. |
I have been thinking of this as well. What is the status of this now @agilgur5? Any progress? Inspired by var jsPDF = require('jspdf/lib/core');
require('jspdf/lib/total-pages');
require('jspdf/lib/polyfills');
// Note that require('jspdf') would still import `jspdf.debug.js` and therefore preserve backwards compatibility and would be easier to use for developers Since this only adds a folder with additional dist files it could be done with complete backwards compatibility. Would you accept a PR adding this folder @MrRio? DiscussionAfter reading @agilgur5 comment above I looked up which and where third party code are actually in use by jspdf. Here is a categorized list of current (v1.3.2) included third party code: Dependencies
Plugin dependencies
Polyfills
@agilgur5 also mentions other interesting things, but I think simply enabling importing parts of jspdf would be a good first step. |
@simonbengtsson I have not started this. This requires a fundamental shift in how the library is maintained moving forward (otherwise the proposal is useless), as well as potentially the creation of an umbrella organization, and therefore all the maintainers should agree to this. As you can see, not a single one, including @MrRio, has even replied to my proposal. This is the way all modern libraries are organized, so the hold up is unfortunate. Exporting to a That being said, I like the idea of keeping "complete backwards compatibility" ( Thanks for listing out all the dependencies @simonbengtsson! File-saving and compression I believe should also be opt-in and can also be made as plugins, which would move the first two to "Plugin dependencies". Good note that |
I'd really appreciate some work in this direction. Can you comment on this idea, @MrRio? |
I agree with all your points @agilgur5. However I'm leaning towards that the complexity of having different repos would not be worth it. It might be easier to go for the monorepo approach for now. At least until an active maintainer wants to take responsibility of a certain plugin. |
@simonbengtsson using In any case, I don't see much value in discussing repository structure unless one of us will be an active maintainer, as all the current maintainers are inactive and don't follow any modern repository structure techniques yet. |
I think we need to fix this soon. I agree that we need to modernise the way jsPDF can be imported. Thank you for your comments so far. |
Our current plan is to try and get any currently working and mergeable PRs merged before the refactor starts. The main one is utf-8 support. We’ll then format using StandardJS or a popular ESLint config, then we’ll start modernising each file. The way the plugins are currently make them very ‘pick and mix’. We should try slim down the core also, but we need to run some analysis on which plugins rely on which feature. |
@MrRio |
Something I coded for fun and PoC https://arasabbasi.github.io/jsPDF/builder/index.html |
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. |
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant. |
That would be sad so will comment to keep it open. |
Yes, this is definitively a good idea but impossible without extensive help from the community. #2804 is a small step in the right direction (at least the polyfills are no longer bundled). Let's keep this open for the future. |
This is an amazing idea ! |
Would a PR with the libs dist folder discussed above be considered for merge? If so I can make an attempt. |
@simonbengtsson a pull request would be very much appreciated :) You can probably base on the changes I made in #2804 and add a couple more entry points to the rollup config for the files in the dist/lib folder. Things to discuss:
I think the first two options are better than the third one, because the folders won't be as cluttered in code completion, etc.
What are your thoughts? Before you start with the pull request, I think it is best if I merge #2804 first. |
#2804 is merged now. |
The |
Good idea |
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
anddownloadify
when I don't even use them. Or all ofrequirejs
(which causes compatibility problems very easily),Blob.js
, and thecanvas
implementation, if I don't need them. etc. etc.With a modular build I would do something like:
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
The text was updated successfully, but these errors were encountered: