Skip to content

Commit bc215ea

Browse files
committed
fix: web build .mjs assets renamed to .js so PDF.js worker loads
The previous fix (6194e8b) only set entryFileNames + chunkFileNames, which covers entry chunks and dynamic-import chunks but NOT assets. PDF.js loads its worker via new URL('pdfjs-dist/build/pdf.worker.mjs', import.meta.url) which Vite handles as an asset import — controlled by assetFileNames, not chunkFileNames. So the worker kept its .mjs extension and the web host couldn't fetch it. Adds a function-form assetFileNames that renames any .mjs asset to .js while leaving CSS / images / fonts untouched. Verified the worker now ships as `pdf.worker-HASH.js` in the local build output.
1 parent 49e7db5 commit bc215ea

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

open-pdf-studio/vite.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,24 @@ export default defineConfig({
3131
chunkSizeWarningLimit: 6000,
3232
rollupOptions: {
3333
output: {
34+
// Force .js extensions on entry chunks and dynamic-import chunks
35+
// so the web host serves them with the correct MIME type
36+
// (some hosts return application/octet-stream for .mjs).
3437
entryFileNames: 'assets/[name]-[hash].js',
3538
chunkFileNames: 'assets/[name]-[hash].js',
39+
// Same treatment for assets, but ONLY for .mjs files (don't touch
40+
// CSS, images, fonts, etc). PDF.js's worker is loaded via
41+
// new URL('pdfjs-dist/build/pdf.worker.mjs', import.meta.url)
42+
// which Vite handles as an asset import — without this, the
43+
// worker is emitted as `pdf.worker-HASH.mjs` and the web build
44+
// can't fetch it.
45+
assetFileNames: (assetInfo) => {
46+
const name = assetInfo.name || '';
47+
if (name.endsWith('.mjs')) {
48+
return 'assets/[name]-[hash].js';
49+
}
50+
return 'assets/[name]-[hash][extname]';
51+
},
3652
},
3753
},
3854
},

0 commit comments

Comments
 (0)