PublicPathRuntimeModule.js 663 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. const RuntimeGlobals = require("../RuntimeGlobals");
  6. const RuntimeModule = require("../RuntimeModule");
  7. class PublicPathRuntimeModule extends RuntimeModule {
  8. constructor(publicPath) {
  9. super("publicPath", RuntimeModule.STAGE_BASIC);
  10. this.publicPath = publicPath;
  11. }
  12. /**
  13. * @returns {string} runtime code
  14. */
  15. generate() {
  16. const { compilation, publicPath } = this;
  17. return `${RuntimeGlobals.publicPath} = ${JSON.stringify(
  18. compilation.getPath(publicPath || "", {
  19. hash: compilation.hash || "XXXX"
  20. })
  21. )};`;
  22. }
  23. }
  24. module.exports = PublicPathRuntimeModule;