1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | const RuntimeGlobals = require("../RuntimeGlobals");
|
8 | const RuntimeModule = require("../RuntimeModule");
|
9 | const Template = require("../Template");
|
10 |
|
11 |
|
12 |
|
13 | class GetMainFilenameRuntimeModule extends RuntimeModule {
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 | constructor(name, global, filename) {
|
20 | super(`get ${name} filename`);
|
21 | this.global = global;
|
22 | this.filename = filename;
|
23 | }
|
24 |
|
25 | |
26 |
|
27 |
|
28 | generate() {
|
29 | const { global, filename, compilation, chunk } = this;
|
30 | const { runtimeTemplate } = compilation;
|
31 | const url = compilation.getPath(JSON.stringify(filename), {
|
32 | hash: `" + ${RuntimeGlobals.getFullHash}() + "`,
|
33 | hashWithLength: length =>
|
34 | `" + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
|
35 | chunk,
|
36 | runtime: chunk.runtime
|
37 | });
|
38 | return Template.asString([
|
39 | `${global} = ${runtimeTemplate.returningFunction(url)};`
|
40 | ]);
|
41 | }
|
42 | }
|
43 |
|
44 | module.exports = GetMainFilenameRuntimeModule;
|