mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-11-30 16:37:18 +01:00
Configure Gulp to emit named Firefox worker chunks
This commit is contained in:
+8
-2
@@ -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 }) => {
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user