Pdf.js: Large webpack bundle

Created on 31 Oct 2017  路  4Comments  路  Source: mozilla/pdf.js

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!

Most helpful comment

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.

All 4 comments

See https://github.com/mozilla/pdf.js/tree/master/examples/webpack. Don't use lib folder files.

Closing as answered.

I started with the example. The example creates a 2 files:
main.bundle.js: 441KB
1.1.bundle.js: 731KB

Which is even larger then my example.
Can this be reopened?

Yes, these are correct sizes for PDF.js applications.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zerr0s picture zerr0s  路  3Comments

xingxiaoyiyio picture xingxiaoyiyio  路  3Comments

anggikolo11 picture anggikolo11  路  3Comments

patelsumit5192 picture patelsumit5192  路  3Comments

timvandermeij picture timvandermeij  路  4Comments