BaseUriRuntimeModule.js 894 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Ivan Kopeykin @vankop
  4. */
  5. "use strict";
  6. const RuntimeGlobals = require("../RuntimeGlobals");
  7. const RuntimeModule = require("../RuntimeModule");
  8. /** @typedef {import("../../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescriptionNormalized */
  9. /** @typedef {import("../Chunk")} Chunk */
  10. class BaseUriRuntimeModule extends RuntimeModule {
  11. constructor() {
  12. super("base uri", RuntimeModule.STAGE_ATTACH);
  13. }
  14. /**
  15. * @returns {string | null} runtime code
  16. */
  17. generate() {
  18. const chunk = /** @type {Chunk} */ (this.chunk);
  19. const options =
  20. /** @type {EntryDescriptionNormalized} */
  21. (chunk.getEntryOptions());
  22. return `${RuntimeGlobals.baseURI} = ${
  23. options.baseUri === undefined
  24. ? "undefined"
  25. : JSON.stringify(options.baseUri)
  26. };`;
  27. }
  28. }
  29. module.exports = BaseUriRuntimeModule;