2018-11-20 19:05:12 +08:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
2018-11-20 19:05:12 +08:00
|
|
|
class PublicPathRuntimeModule extends RuntimeModule {
|
2021-04-14 22:38:01 +08:00
|
|
|
constructor(publicPath) {
|
2020-12-11 21:32:42 +08:00
|
|
|
super("publicPath", RuntimeModule.STAGE_BASIC);
|
2021-04-14 22:38:01 +08:00
|
|
|
this.publicPath = publicPath;
|
2018-11-20 19:05:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string} runtime code
|
|
|
|
*/
|
|
|
|
generate() {
|
2021-04-14 22:38:01 +08:00
|
|
|
const { compilation, publicPath } = this;
|
2020-09-15 05:27:38 +08:00
|
|
|
|
2020-09-18 16:12:13 +08:00
|
|
|
return `${RuntimeGlobals.publicPath} = ${JSON.stringify(
|
2021-04-14 22:38:01 +08:00
|
|
|
compilation.getPath(publicPath || "", {
|
|
|
|
hash: compilation.hash || "XXXX"
|
2020-09-15 05:27:38 +08:00
|
|
|
})
|
2020-09-18 16:12:13 +08:00
|
|
|
)};`;
|
2020-09-15 05:27:38 +08:00
|
|
|
}
|
2018-11-20 19:05:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = PublicPathRuntimeModule;
|