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.

Large webpack bundle

See original GitHub issue

When I import PDFJS through webpack the bundlesize is significatly larger than the minified pdf.min.js file provided in pdfjs-dist. pdf.min.js: 299KB webpack bundle: 988KB

my entry file looks like this:

import { PDFJS, getDocument } from 'pdfjs-dist'

or

import { PDFJS } from 'pdfjs-dist/lib/display/global';
import { getDocument } from 'pdfjs-dist/lib/display/api';

webpack 3 config:

const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
    entry: {
        'pdf.js': './example/pdf-js.entry.js'
    },
    output: {
        path: __dirname + '/example/dist',
        filename: '[name].bundle.js'
    },
    plugins: [
        new webpack.optimize.ModuleConcatenationPlugin(),
        new UglifyJSPlugin({
            parallel: true,
            extractComments: true,
            uglifyOptions: {
                output: {
                    comments: false,
                    beautify: false,
                },
                compress: {
                    sequences: false
                }
            }
        }),
        new webpack.optimize.LimitChunkCountPlugin({
            maxChunks: 1,
            minChunkSize: 1000
        })
    ],
};

Is there a way to get to the same bundle size as pdf.min.js? Are there plans to make pdf.js treeshakable?

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
GauravThakur03commented, Sep 3, 2022

Try Adobe Embed APIs: https://www.adobe.com/devnet-docs/dcsdk_io/viewSDK/index.html

  • Much smaller
  • Easy to integrate
  • Much better PDF View quality
  • Lots of PDF features
3reactions
stijndeschuymercommented, Oct 31, 2017

But the minified files from pdfjs-dist are much smaller. Don’t they include the same library? I now include those minified files as script tags in my html instead of bundling them with webpack, and my application runs the same.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack final bundle size is too big - node.js - Stack Overflow
I know I am missing something here. Should be somewhere near to or more than webpack recommendations but 1010 KB is too much....
Read more >
3 ways to reduce webpack bundle size - Jakob Lind
Go through these three steps to get a quick overview of what to do to reduce webpack bundle size. I have listed them...
Read more >
How to Reduce Your Webpack Bundle Size for Web App ...
So I'm gonna try to give you some tips used by teams working on large apps to reduce the size of their main...
Read more >
5 Methods to Reduce JavaScript Bundle Size - Bits and Pieces
1. Code Splitting with Webpack. Code splitting allows you to separate your code into bundles and load them on-demand. There are multiple ways ......
Read more >
How to put your Webpack bundle on a diet - Contentful
Webpack is a static module bundler for JavaScript applications. While it's very useful, Webpack can sometimes create unnecessarily large bundles ...
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