I need to use PDF.js with Webpack, I followed the documentation that tells you to add an entry for pdf.worker.
Here is the entry and output of my webpack config:
entry: {
index: './src/client/home/home.jsx',
'pdf.worker': 'pdfjs-dist/build/pdf.worker.entry'
},
output: {
path: path.join(__dirname, 'build/client'),
publicPath: '/',
filename: [name]-[chunkhash].js,
}
And still according to the documentation, in the javacript code, I need to specify the worker path like this:
pdfjsLib.PDFJS.workerSrc = '/pdf.worker.bundle.js';
The issue is that I use chunkhash for the generation of the file so it cannot find pdf.worker.bundle.js.
I see two solutions:
Remove the hash for the worker ONLY in webpack: [name]-bundle.js But how can I tell webpack to ONLY do this for the worker and not the other .js files?
Change the value of pdfjsLib.PDFJS.workerSrc after the code is generated, how can I do that?
Also, am I right to think that the first solution is not good since the user will always cache the same worker?