RuntimeIdRuntimeModule.js 685 B

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