Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new output option, workerPublicPath #16671

Merged
merged 32 commits into from Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
895df2a
Worker public path changes
thomastay Oct 21, 2022
c188270
Merge branch 'webpack:main' into main
thomastay Jan 25, 2023
0df564b
Make workerPublicPath optional and update docs
thomastay Jan 25, 2023
7a1ccea
change json schema description
thomastay Jan 25, 2023
2e64c44
add into output schema
thomastay Jan 25, 2023
13be78b
lint fixes
thomastay Jan 25, 2023
674dd74
serialize and update hash per options
thomastay Jan 26, 2023
8676f74
Add statsCase - the different asset hashes show that worker public pa…
thomastay Jan 26, 2023
1eb549b
remove TODO comment
thomastay Jan 26, 2023
5c03c4f
accidentally added a dummy file, removed
thomastay Jan 26, 2023
292dd48
Add in a config case as well
thomastay Jan 26, 2023
ee2c87b
lint
thomastay Jan 26, 2023
e5fd6a4
update snapshots
thomastay Jan 26, 2023
7ef871b
lint fix (somehow by version of Prettier adds this but on linux it do…
thomastay Jan 27, 2023
0636863
Merge branch 'webpack:main' into main
thomastay Feb 9, 2023
0d91c55
Fix CI build failures due to extranous double quotes and await worker…
thomastay Feb 9, 2023
9e8fe6e
fix Defaults snapshot
thomastay Feb 9, 2023
d33f32d
Updated validation snapshot
thomastay Feb 10, 2023
2a39a0a
No cache for stat test
thomastay Feb 10, 2023
9fa1415
snapshot is cached
thomastay Feb 10, 2023
ea07777
stats test is flaky, revert to just one
thomastay Feb 10, 2023
47e1440
read/write options as a whole (follow ConsumeSharedModule)
thomastay Feb 10, 2023
6e21e6e
Update schemas/WebpackOptions.json
TheLarkInn Mar 3, 2023
954d98a
special lint fix
thomastay Mar 15, 2023
9e3f5bb
update snapshots and more special lint fix
thomastay Mar 16, 2023
4b4c6a1
update snapshots according to CI
thomastay Mar 16, 2023
2822ed3
weird case where snapshots have extra spaces
thomastay Mar 16, 2023
460ed46
asset hash
thomastay Mar 16, 2023
628125f
revert weird space issues
thomastay Mar 22, 2023
2cad865
change hash
thomastay Mar 22, 2023
f33c2b0
Merge branch 'webpack:main' into main
thomastay Mar 22, 2023
8c6a1a4
revert weird space issues part 2
thomastay Mar 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions declarations/WebpackOptions.d.ts
Expand Up @@ -569,6 +569,10 @@ export type UniqueName = string;
* The filename of WebAssembly modules as relative path inside the 'output.path' directory.
*/
export type WebassemblyModuleFilename = string;
/**
* 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;
/**
* The number of parallel processed modules in the compilation.
*/
Expand Down Expand Up @@ -2164,6 +2168,10 @@ export interface Output {
* The method of loading chunks (methods included by default are 'jsonp' (web), 'import' (ESM), 'importScripts' (WebWorker), 'require' (sync node.js), 'async-node' (async node.js), but others might be added by plugins).
*/
workerChunkLoading?: ChunkLoading;
/**
* 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;
/**
* The method of loading WebAssembly Modules (methods included by default are 'fetch' (web/WebWorker), 'async-node' (node.js), but others might be added by plugins).
*/
Expand Down Expand Up @@ -3349,6 +3357,10 @@ export interface OutputNormalized {
* The method of loading chunks (methods included by default are 'jsonp' (web), 'import' (ESM), 'importScripts' (WebWorker), 'require' (sync node.js), 'async-node' (async node.js), but others might be added by plugins).
*/
workerChunkLoading?: ChunkLoading;
/**
* 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;
/**
* The method of loading WebAssembly Modules (methods included by default are 'fetch' (web/WebWorker), 'async-node' (node.js), but others might be added by plugins).
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/WebpackOptionsApply.js
Expand Up @@ -391,7 +391,8 @@ class WebpackOptionsApply extends OptionsApply {
new WorkerPlugin(
options.output.workerChunkLoading,
options.output.workerWasmLoading,
options.output.module
options.output.module,
options.output.workerPublicPath
).apply(compiler);

new DefaultStatsFactoryPlugin().apply(compiler);
Expand Down
1 change: 1 addition & 0 deletions lib/config/defaults.js
Expand Up @@ -916,6 +916,7 @@ const applyOutputDefaults = (
? "auto"
: ""
);
D(output, "workerPublicPath", "");
D(output, "chunkLoadTimeout", 120000);
D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
D(output, "hashDigest", "hex");
Expand Down
1 change: 1 addition & 0 deletions lib/config/normalization.js
Expand Up @@ -369,6 +369,7 @@ const getNormalizedWebpackOptions = config => {
uniqueName: output.uniqueName,
wasmLoading: output.wasmLoading,
webassemblyModuleFilename: output.webassemblyModuleFilename,
workerPublicPath: output.workerPublicPath,
workerChunkLoading: output.workerChunkLoading,
workerWasmLoading: output.workerWasmLoading
};
Expand Down
14 changes: 10 additions & 4 deletions lib/dependencies/WorkerDependency.js
Expand Up @@ -25,10 +25,13 @@ class WorkerDependency extends ModuleDependency {
/**
* @param {string} request request
* @param {[number, number]} range range
* @param {Object} workerDependencyOptions options
* @param {string} workerDependencyOptions.publicPath public path for the worker
*/
constructor(request, range) {
constructor(request, range, workerDependencyOptions) {
super(request);
this.range = range;
this.options = workerDependencyOptions;
TheLarkInn marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -77,9 +80,12 @@ WorkerDependency.Template = class WorkerDependencyTemplate extends (
source.replace(
dep.range[0],
dep.range[1] - 1,
`/* worker import */ ${RuntimeGlobals.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}`
);
}
};
Expand Down
7 changes: 5 additions & 2 deletions lib/dependencies/WorkerPlugin.js
Expand Up @@ -48,10 +48,11 @@ const DEFAULT_SYNTAX = [
const workerIndexMap = new WeakMap();

class WorkerPlugin {
constructor(chunkLoading, wasmLoading, module) {
constructor(chunkLoading, wasmLoading, module, workerPublicPath) {
this._chunkLoading = chunkLoading;
this._wasmLoading = wasmLoading;
this._module = module;
this._workerPublicPath = workerPublicPath;
}
/**
* Apply the plugin
Expand Down Expand Up @@ -298,7 +299,9 @@ class WorkerPlugin {
}
});
block.loc = expr.loc;
const dep = new WorkerDependency(url.string, range);
const dep = new WorkerDependency(url.string, range, {
publicPath: this._workerPublicPath
});
dep.loc = expr.loc;
block.addDependency(dep);
parser.state.module.addBlock(block);
Expand Down
2 changes: 1 addition & 1 deletion schemas/WebpackOptions.check.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions schemas/WebpackOptions.json
Expand Up @@ -3241,6 +3241,9 @@
"workerChunkLoading": {
"$ref": "#/definitions/ChunkLoading"
},
"workerPublicPath": {
"$ref": "#/definitions/WorkerPublicPath"
},
"workerWasmLoading": {
"$ref": "#/definitions/WasmLoading"
}
Expand Down Expand Up @@ -3397,6 +3400,9 @@
"workerChunkLoading": {
"$ref": "#/definitions/ChunkLoading"
},
"workerPublicPath": {
"$ref": "#/definitions/WorkerPublicPath"
},
"workerWasmLoading": {
"$ref": "#/definitions/WasmLoading"
}
Expand Down Expand Up @@ -5271,6 +5277,10 @@
}
},
"required": ["apply"]
},
"WorkerPublicPath": {
"description": "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.",
TheLarkInn marked this conversation as resolved.
Show resolved Hide resolved
"type": "string"
}
},
"title": "WebpackOptions",
Expand Down
11 changes: 11 additions & 0 deletions types.d.ts
Expand Up @@ -6543,6 +6543,7 @@ declare interface LoaderRunnerLoaderContext<OptionsType> {
/**
* An array of all the loaders. It is writeable in the pitch phase.
* loaders = [{request: string, path: string, query: string, module: function}]
*
* In the example:
* [
* { request: "/abc/loader1.js?xyz",
Expand Down Expand Up @@ -8674,6 +8675,11 @@ declare interface Output {
*/
workerChunkLoading?: string | false;

/**
* 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?: string;

/**
* The method of loading WebAssembly Modules (methods included by default are 'fetch' (web/WebWorker), 'async-node' (node.js), but others might be added by plugins).
*/
Expand Down Expand Up @@ -8968,6 +8974,11 @@ declare interface OutputNormalized {
*/
workerChunkLoading?: string | false;

/**
* 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?: string;

/**
* The method of loading WebAssembly Modules (methods included by default are 'fetch' (web/WebWorker), 'async-node' (node.js), but others might be added by plugins).
*/
Expand Down