Configure Gulp to emit named Firefox worker chunks

This commit is contained in:
Calixte Denizet
2026-11-20 17:28:27 +01:00
parent 87f2fa772d
commit 5808a188a5
2 changed files with 33 additions and 2 deletions
+8 -2
View File
@@ -68,8 +68,14 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
return { return {
name: "babel-plugin-pdfjs-preprocessor", name: "babel-plugin-pdfjs-preprocessor",
manipulateOptions({ parserOpts }) { manipulateOptions({ parserOpts, generatorOpts }) {
parserOpts.attachComment = false; const namedWorkerChunks =
ctx.defines?.MOZCENTRAL && ctx.defines.WORKER_THREAD;
parserOpts.attachComment = !!namedWorkerChunks;
if (namedWorkerChunks) {
generatorOpts.shouldPrintComment = comment =>
/webpack(?:ChunkName|Ignore|Mode):|@vite-ignore/.test(comment);
}
}, },
visitor: { visitor: {
"ExportNamedDeclaration|ImportDeclaration": ({ node }) => { "ExportNamedDeclaration|ImportDeclaration": ({ node }) => {
+25
View File
@@ -657,10 +657,35 @@ function createWorkerBundle(defines) {
}; };
const workerFileConfig = createWebpackConfig(workerDefines, { const workerFileConfig = createWebpackConfig(workerDefines, {
filename: workerDefines.MINIFIED ? "pdf.worker.min.mjs" : "pdf.worker.mjs", filename: workerDefines.MINIFIED ? "pdf.worker.min.mjs" : "pdf.worker.mjs",
// Keep the standalone worker used by generic builds self-contained.
asyncChunks: workerDefines.MOZCENTRAL,
...(workerDefines.MOZCENTRAL && {
chunkFilename: "pdf.worker.[name].mjs",
chunkFormat: "module",
chunkLoading: "import",
}),
library: { library: {
type: "module", type: "module",
}, },
}); });
if (workerDefines.MOZCENTRAL) {
workerFileConfig.optimization.chunkIds = "named";
workerFileConfig.optimization.splitChunks = {
cacheGroups: {
default: {
// Keep the XHTML parser in both chunks so each can load on its own.
test: module =>
!/[/\\]src[/\\]core[/\\]xfa[/\\]/.test(module.nameForCondition()),
idHint: "",
minChunks: 2,
// Share small modules too, e.g. the writer.
minSize: 0,
priority: -20,
reuseExistingChunk: true,
},
},
};
}
return createWebpackStream("./src/pdf.worker.js", workerFileConfig); return createWebpackStream("./src/pdf.worker.js", workerFileConfig);
} }