getPaths.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 =
  19. /** @type {MultiStats} */
  20. stats.stats ?
  21. /** @type {MultiStats} */
  22. stats.stats : [
  23. /** @type {Stats} */
  24. stats];
  25. const publicPaths = [];
  26. for (const {
  27. compilation
  28. } of childStats) {
  29. // The `output.path` is always present and always absolute
  30. const outputPath = compilation.getPath(compilation.outputOptions.path || "");
  31. const publicPath = options.publicPath ? compilation.getPath(options.publicPath) : compilation.outputOptions.publicPath ? compilation.getPath(compilation.outputOptions.publicPath) : "";
  32. publicPaths.push({
  33. outputPath,
  34. publicPath
  35. });
  36. }
  37. return publicPaths;
  38. }
  39. module.exports = getPaths;