Make workerPublicPath optional and update docs

This commit is contained in:
Thomas Tay 2023-01-25 12:17:15 -08:00
parent c188270d13
commit 0df564bc98
2 changed files with 8 additions and 5 deletions

View File

@ -570,7 +570,7 @@ export type UniqueName = string;
*/
export type WebassemblyModuleFilename = string;
/**
* Worker public path.
* Worker public path. Much like the public path, this sets the location that the worker script file is intended to be found at. If not set, Webpack will use the publicPath. Don't set this option unless your worker scripts are located at a different path from your other script files.
*/
export type WorkerPublicPath = string;
/**
@ -2169,7 +2169,7 @@ export interface Output {
*/
workerChunkLoading?: ChunkLoading;
/**
* Worker public path.
* Worker public path. Much like the public path, this sets the location that the worker script file is intended to be found at. If not set, Webpack will use the publicPath. Don't set this option unless your worker scripts are located at a different path from your other script files.
*/
workerPublicPath?: WorkerPublicPath;
/**

View File

@ -80,9 +80,12 @@ WorkerDependency.Template = class WorkerDependencyTemplate extends (
source.replace(
dep.range[0],
dep.range[1] - 1,
`/* worker import */ "${dep.options.publicPath}" + ${
RuntimeGlobals.getChunkScriptFilename
}(${JSON.stringify(chunk.id)}), ${RuntimeGlobals.baseURI}`
`/* worker import */ "${
// We use the workerPublicPath option if provided, else we fallback to the RuntimeGlobal publicPath
dep.options.publicPath || RuntimeGlobals.publicPath
}" + ${RuntimeGlobals.getChunkScriptFilename}(${JSON.stringify(
chunk.id
)}), ${RuntimeGlobals.baseURI}`
);
}
};