pdf.js/examples/webpack
Jonas Jenwald d53093045a Enable the import/no-commonjs ESLint plugin rule
Given the amount of work put into removing `require`-calls from the code-base, let's ensure that new ones aren't accidentally added in the future.

Note that we still have a couple of files where `require` is being used, in particular:
 - The Node.js examples, however those will be updated to use `import` in PR 17081.
 - The Webpack examples, and related support files, however I unfortunately don't know enough about Webpack to be able to update those. (Hopefully users of that code will help out here, once version `4` is released.)
 - The `statcmp`-tool, since *some* of those `require`-calls cannot be converted to `import` without other code changes (and that file is only used during benchmarking).

Please find additional details at https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-commonjs.md
2023-10-14 12:49:17 +02:00
..
.eslintrc Manually fix remaining ESLint errors 2018-12-11 15:23:26 +01:00
.gitignore Adds/modifies examples for node.js and webpack. 2015-12-21 13:46:50 -06:00
index.html Removing "entry-loader" dependency from webpack. 2016-04-13 08:24:25 -05:00
main.js Enable the import/no-commonjs ESLint plugin rule 2023-10-14 12:49:17 +02:00
package.json Update the webpack-versions used in examples/webpack 2021-01-05 12:42:11 +01:00
README.md [api-minor] Use new Worker() syntax in webpack entrypoint 2022-09-13 11:12:00 -04:00
webpack.config.js Enable the import/no-commonjs ESLint plugin rule 2023-10-14 12:49:17 +02:00

Overview

Example to demonstrate PDF.js library usage with Webpack.

Getting started

Install the example dependencies and build the project:

$ gulp dist-install
$ cd examples/webpack
$ npm install
$ ./node_modules/webpack/bin/webpack.js

You can observe the build results by running gulp server and navigating to http://localhost:8888/examples/webpack/index.html.

Refer to the main.js and webpack.config.js files for the source code. Note that PDF.js packaging requires packaging of the main application and the worker code, and the workerSrc path shall be set to the latter file.

Minification

If you are configuring Webpack to output a minified build, please note that you must configure the minifier to keep original class/function names intact; otherwise the build is not guaranteed to work correctly.

Worker loading

If you are getting the Setting up fake worker warning, make sure you are importing pdfjs-dist/webpack which is the zero-configuration method for Webpack users. Installing worker-loader is no longer necessary.

import * as pdfjsLib from 'pdfjs-dist/webpack';

For a full working example refer to this repository.