webpack/lib/runtime/PublicPathRuntimeModule.js

38 lines
949 B
JavaScript
Raw Normal View History

/*
MIT License http://www.opensource.org/licenses/mit-license.php
*/
"use strict";
const RuntimeGlobals = require("../RuntimeGlobals");
const RuntimeModule = require("../RuntimeModule");
2018-12-18 05:05:08 +08:00
2023-05-25 03:37:58 +08:00
/** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
2023-06-13 01:24:59 +08:00
/** @typedef {import("../Compilation")} Compilation */
2023-05-25 03:37:58 +08:00
class PublicPathRuntimeModule extends RuntimeModule {
2023-05-25 03:37:58 +08:00
/**
* @param {OutputOptions["publicPath"]} publicPath public path
*/
constructor(publicPath) {
super("publicPath", RuntimeModule.STAGE_BASIC);
this.publicPath = publicPath;
}
/**
2023-06-17 01:13:03 +08:00
* @returns {string | null} runtime code
*/
generate() {
2023-06-13 01:24:59 +08:00
const { publicPath } = this;
const compilation = /** @type {Compilation} */ (this.compilation);
return `${RuntimeGlobals.publicPath} = ${JSON.stringify(
compilation.getPath(publicPath || "", {
hash: compilation.hash || "XXXX"
})
)};`;
}
}
module.exports = PublicPathRuntimeModule;