Fix pdfjs-dist/webpack causing errors with certain configs
Using `require.resolve("worker-loader")` to check if `worker-loader` is installed causes webpack to include `worker-loader` in the output bundle, which is not the intended effect. Aside from increasing the bundle size unnecessarily, it also causes errors for webpack configs with targets that don't have node's built-in modules. These errors can be fixed by configuring webpack `externals` to exclude `worker-loader`, but it's more difficult to figure out this solution than to figure out that `worker-loader` needs to be installed (even without this explicit error message). To solve this, the explicit check for `worker-loader` has been removed. An alternative solution would be to use webpack's `resolveWeak`. Documentation has also been added in `examples/webpack` to help users.
This commit is contained in:
parent
96ad60f116
commit
3b9031f6a3
@ -20,7 +20,12 @@ the worker code, and the `workerSrc` path shall be set to the latter file.
|
|||||||
|
|
||||||
## Worker loading
|
## 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:
|
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. You will need to install
|
||||||
|
[worker-loader](https://github.com/webpack-contrib/worker-loader) as a
|
||||||
|
dependency in your project in order to use `pdfjs-dist/webpack` (configuring
|
||||||
|
`worker-loader` is not necessary; just installing it is sufficient).
|
||||||
|
|
||||||
import pdfjsLib from 'pdfjs-dist/webpack';
|
import pdfjsLib from 'pdfjs-dist/webpack';
|
||||||
|
|
||||||
|
8
external/dist/webpack.js
vendored
8
external/dist/webpack.js
vendored
@ -15,14 +15,6 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
try {
|
|
||||||
require.resolve("worker-loader");
|
|
||||||
} catch (ex) {
|
|
||||||
throw new Error(
|
|
||||||
"Cannot find the `worker-loader` package, please make sure that it's correctly installed."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
var pdfjs = require("./build/pdf.js");
|
var pdfjs = require("./build/pdf.js");
|
||||||
var PdfjsWorker = require("worker-loader!./build/pdf.worker.js");
|
var PdfjsWorker = require("worker-loader!./build/pdf.worker.js");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user