Cannot specify web worker src location (specifically prevents use of PDF.js)
See original GitHub issueThis issue has been generated from a comment by @gaearon in #1015. This issue will probably want to be labelled as a discussion. The objective of raising this issue is to capture a real-world use case to be resolved.
Essentially my objective is to be able to use PDF.js in my application. In order to do this I need to be able to configure the workerSrc
attribute on the PDFJS global object.
The recommended approach (as described in this example) is to add a new entry into the webpack configuration so that a new bundle will be generated (just containing the worker source) and then pass a relative path to that bundle.
i.e. in webpack.config.js
entry: {
'main': './main.js',
'pdf.worker': 'pdfjs-dist/build/pdf.worker.entry'
},
then when using PDF.js
var pdfjsLib = require('pdfjs-dist');
// Setting worker path to worker bundle.
pdfjsLib.PDFJS.workerSrc = '../../build/webpack/pdf.worker.bundle.js';
Unfortunately #1084 deals with the requirement to add additional entries (which at the time of writing is still unresolved). I’ve raised this as a separate issue because although there is some overlap the is a specific requirement here to enable relative paths to JS files to be specified that can still be resolved as individual files after build… adding additional entries is one solution, but is entirely dependent upon webpack and my understanding is that a more generic solution (not specific to webpack) is required.
I’ve explored some other solutions (like using file-loader as described for this project) and have also explored using require.ensure.
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (5 by maintainers)
Another option I’ve just realised is to copy the worker source file to the public folder and reference is like this:
This also seems to work within the application, but for my specific use case (I’m using create react app as a development environment to build re-usable components that I’m then publishing to NPM) this won’t work… but as a solution just within create react app this would definitely work.
I’m happy to close this issue as my specific requirements are almost certainly outside the scope of this project.
Thanks for raising this! It’s an interesting use case. We’ll keep this in mind when we consider supporting multiple entries.