UNPKG

685 BJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3*/
4
5"use strict";
6
7const RuntimeGlobals = require("../RuntimeGlobals");
8const RuntimeModule = require("../RuntimeModule");
9
10class RuntimeIdRuntimeModule extends RuntimeModule {
11 constructor() {
12 super("runtimeId");
13 }
14
15 /**
16 * @returns {string} runtime code
17 */
18 generate() {
19 const { chunkGraph, chunk } = this;
20 const runtime = chunk.runtime;
21 if (typeof runtime !== "string")
22 throw new Error("RuntimeIdRuntimeModule must be in a single runtime");
23 const id = chunkGraph.getRuntimeId(runtime);
24 return `${RuntimeGlobals.runtimeId} = ${JSON.stringify(id)};`;
25 }
26}
27
28module.exports = RuntimeIdRuntimeModule;