webpack/lib/runtime/BaseUriRuntimeModule.js

36 lines
894 B
JavaScript
Raw Normal View History

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Ivan Kopeykin @vankop
*/
"use strict";
const RuntimeGlobals = require("../RuntimeGlobals");
const RuntimeModule = require("../RuntimeModule");
2023-05-25 03:37:58 +08:00
/** @typedef {import("../../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescriptionNormalized */
2023-06-13 01:24:59 +08:00
/** @typedef {import("../Chunk")} Chunk */
2023-05-25 03:37:58 +08:00
class BaseUriRuntimeModule extends RuntimeModule {
constructor() {
super("base uri", RuntimeModule.STAGE_ATTACH);
}
/**
2023-06-17 01:13:03 +08:00
* @returns {string | null} runtime code
*/
generate() {
2023-06-13 01:24:59 +08:00
const chunk = /** @type {Chunk} */ (this.chunk);
2023-05-25 03:37:58 +08:00
const options =
/** @type {EntryDescriptionNormalized} */
(chunk.getEntryOptions());
return `${RuntimeGlobals.baseURI} = ${
options.baseUri === undefined
? "undefined"
: JSON.stringify(options.baseUri)
};`;
}
}
module.exports = BaseUriRuntimeModule;