getPaths.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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").FilledContext<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. if (compilation.options.devServer === false) {
  25. // eslint-disable-next-line no-continue
  26. continue;
  27. }
  28. // The `output.path` is always present and always absolute
  29. const outputPath = compilation.getPath(compilation.outputOptions.path || "");
  30. const publicPath = options.publicPath ? compilation.getPath(options.publicPath) : compilation.outputOptions.publicPath ? compilation.getPath(compilation.outputOptions.publicPath) : "";
  31. publicPaths.push({
  32. outputPath,
  33. publicPath,
  34. assetsInfo: compilation.assetsInfo
  35. });
  36. }
  37. return publicPaths;
  38. }
  39. module.exports = getPaths;