Skip to content
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

Making pdfmake.js optional #1507

Closed
nicolaric opened this issue May 6, 2024 · 3 comments
Closed

Making pdfmake.js optional #1507

nicolaric opened this issue May 6, 2024 · 3 comments

Comments

@nicolaric
Copy link

Question

We try to minimize our package size of the application to improve loading times. Since we migrated the whole project from AMCharts4 to AMCharts5 now, we saved a noteable amount of MBs. Now, one of the biggest packages left is pdfmake.js (close to 1MB), which is used by amcharts5. We don't use the PDF functionality in our project though. Is there a possibility to make this package optional or treeshakable in the project without going through webpack tweaks?

Thanks a lot in advance!

image
@nicolaric
Copy link
Author

maybe this could help as well?
bpampuch/pdfmake#1374

@Pauan
Copy link
Collaborator

Pauan commented May 7, 2024

@nicolaric pdfmake is already optional, amCharts uses dynamic import() which will only load the file when you actually use it.

So if you never export to PDF, then the file will never be loaded, and so it will not have any performance penalty at all.

You can confirm this by using the Chrome / Firefox devtools (the Network tab).

So you don't have to worry about it, pdfmake will not increase the bundle size, and it won't hurt performance.

It has no impact at all on loading times.


However, if you really do want to avoid the file completely, then you will need to change your Webpack configuration to ignore those modules:

https://www.amcharts.com/docs/v4/getting-started/integrations/using-webpack/#Large_file_sizes

  externals: function (context, request, callback) {
    if (/xlsx|canvg|pdfmake/.test(request)) {
      return callback(null, "commonjs " + request);
    }
    callback();
  }

Copy link

github-actions bot commented Jun 7, 2024

This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants