getPaths.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. /** @typedef {import("webpack").Compiler} Compiler */
  3. /** @typedef {import("webpack").Stats} Stats */
  4. /** @typedef {import("webpack").MultiStats} MultiStats */
  5. /** @typedef {import("../index.js").IncomingMessage} IncomingMessage */
  6. /** @typedef {import("../index.js").ServerResponse} ServerResponse */
  7. /**
  8. * @template {IncomingMessage} Request
  9. * @template {ServerResponse} Response
  10. * @param {import("../index.js").Context<Request, Response>} context
  11. */
  12. function getPaths(context) {
  13. const {
  14. stats,
  15. options
  16. } = context;
  17. /** @type {Stats[]} */
  18. const childStats = /** @type {MultiStats} */
  19. stats.stats ? /** @type {MultiStats} */stats.stats : [/** @type {Stats} */stats];
  20. const publicPaths = [];
  21. for (const {
  22. compilation
  23. } of childStats) {
  24. // The `output.path` is always present and always absolute
  25. const outputPath = compilation.getPath(compilation.outputOptions.path || "");
  26. const publicPath = options.publicPath ? compilation.getPath(options.publicPath) : compilation.outputOptions.publicPath ? compilation.getPath(compilation.outputOptions.publicPath) : "";
  27. publicPaths.push({
  28. outputPath,
  29. publicPath
  30. });
  31. }
  32. return publicPaths;
  33. }
  34. module.exports = getPaths;