123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- "use strict";
- const Dependency = require("../Dependency");
- const RuntimeGlobals = require("../RuntimeGlobals");
- const makeSerializable = require("../util/makeSerializable");
- const ModuleDependency = require("./ModuleDependency");
- class WorkerDependency extends ModuleDependency {
-
- constructor(request, range, workerDependencyOptions) {
- super(request);
- this.range = range;
-
- this.options = workerDependencyOptions;
-
- this._hashUpdate = undefined;
- }
-
- getReferencedExports(moduleGraph, runtime) {
- return Dependency.NO_EXPORTS_REFERENCED;
- }
- get type() {
- return "new Worker()";
- }
- get category() {
- return "worker";
- }
-
- updateHash(hash, context) {
- if (this._hashUpdate === undefined) {
- this._hashUpdate = JSON.stringify(this.options);
- }
- hash.update(this._hashUpdate);
- }
-
- serialize(context) {
- const { write } = context;
- write(this.options);
- super.serialize(context);
- }
-
- deserialize(context) {
- const { read } = context;
- this.options = read();
- super.deserialize(context);
- }
- }
- WorkerDependency.Template = class WorkerDependencyTemplate extends (
- ModuleDependency.Template
- ) {
-
- apply(dependency, source, templateContext) {
- const { chunkGraph, moduleGraph, runtimeRequirements } = templateContext;
- const dep = (dependency);
- const block = (
- moduleGraph.getParentBlock(dependency)
- );
- const entrypoint = (
- chunkGraph.getBlockChunkGroup(block)
- );
- const chunk = entrypoint.getEntrypointChunk();
-
- const workerImportBaseUrl = dep.options.publicPath
- ? `"${dep.options.publicPath}"`
- : RuntimeGlobals.publicPath;
- runtimeRequirements.add(RuntimeGlobals.publicPath);
- runtimeRequirements.add(RuntimeGlobals.baseURI);
- runtimeRequirements.add(RuntimeGlobals.getChunkScriptFilename);
- source.replace(
- dep.range[0],
- dep.range[1] - 1,
- `/* worker import */ ${workerImportBaseUrl} + ${
- RuntimeGlobals.getChunkScriptFilename
- }(${JSON.stringify(chunk.id)}), ${RuntimeGlobals.baseURI}`
- );
- }
- };
- makeSerializable(WorkerDependency, "webpack/lib/dependencies/WorkerDependency");
- module.exports = WorkerDependency;
|