1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
3 | Author Tobias Koppers @sokra
|
---|
4 | */
|
---|
5 |
|
---|
6 | "use strict";
|
---|
7 |
|
---|
8 | const RuntimeGlobals = require("../RuntimeGlobals");
|
---|
9 | const makeSerializable = require("../util/makeSerializable");
|
---|
10 | const NullDependency = require("./NullDependency");
|
---|
11 |
|
---|
12 | /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
---|
13 | /** @typedef {import("../Dependency")} Dependency */
|
---|
14 | /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
---|
15 |
|
---|
16 | class CreateScriptUrlDependency extends NullDependency {
|
---|
17 | /**
|
---|
18 | * @param {[number, number]} range range
|
---|
19 | */
|
---|
20 | constructor(range) {
|
---|
21 | super();
|
---|
22 | this.range = range;
|
---|
23 | }
|
---|
24 |
|
---|
25 | get type() {
|
---|
26 | return "create script url";
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | CreateScriptUrlDependency.Template = class CreateScriptUrlDependencyTemplate extends (
|
---|
31 | NullDependency.Template
|
---|
32 | ) {
|
---|
33 | /**
|
---|
34 | * @param {Dependency} dependency the dependency for which the template should be applied
|
---|
35 | * @param {ReplaceSource} source the current replace source which can be modified
|
---|
36 | * @param {DependencyTemplateContext} templateContext the context object
|
---|
37 | * @returns {void}
|
---|
38 | */
|
---|
39 | apply(dependency, source, { runtimeRequirements }) {
|
---|
40 | const dep = /** @type {CreateScriptUrlDependency} */ (dependency);
|
---|
41 |
|
---|
42 | runtimeRequirements.add(RuntimeGlobals.createScriptUrl);
|
---|
43 |
|
---|
44 | source.insert(dep.range[0], `${RuntimeGlobals.createScriptUrl}(`);
|
---|
45 | source.insert(dep.range[1], ")");
|
---|
46 | }
|
---|
47 | };
|
---|
48 |
|
---|
49 | makeSerializable(
|
---|
50 | CreateScriptUrlDependency,
|
---|
51 | "webpack/lib/dependencies/CreateScriptUrlDependency"
|
---|
52 | );
|
---|
53 |
|
---|
54 | module.exports = CreateScriptUrlDependency;
|
---|