webpack/lib/runtime/PublicPathRuntimeModule.js

31 lines
647 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
class PublicPathRuntimeModule extends RuntimeModule {
2020-09-18 15:48:53 +08:00
constructor() {
super("publicPath", 5);
}
/**
* @returns {string} runtime code
*/
generate() {
2020-09-18 15:48:53 +08:00
const { compilation } = this;
const { publicPath } = compilation.outputOptions;
return `${RuntimeGlobals.publicPath} = ${JSON.stringify(
this.compilation.getPath(publicPath || "", {
hash: this.compilation.hash || "XXXX"
})
)};`;
}
}
module.exports = PublicPathRuntimeModule;