-
-
Notifications
You must be signed in to change notification settings - Fork 379
/
Copy pathgetPaths.js
48 lines (42 loc) · 1.41 KB
/
getPaths.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/** @typedef {import("webpack").Compiler} Compiler */
/** @typedef {import("webpack").Stats} Stats */
/** @typedef {import("webpack").MultiStats} MultiStats */
/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */
/** @typedef {import("../index.js").ServerResponse} ServerResponse */
/**
* @template {IncomingMessage} Request
* @template {ServerResponse} Response
* @param {import("../index.js").FilledContext<Request, Response>} context
*/
function getPaths(context) {
const { stats, options } = context;
/** @type {Stats[]} */
const childStats =
/** @type {MultiStats} */
(stats).stats
? /** @type {MultiStats} */ (stats).stats
: [/** @type {Stats} */ (stats)];
const publicPaths = [];
for (const { compilation } of childStats) {
if (compilation.options.devServer === false) {
// eslint-disable-next-line no-continue
continue;
}
// The `output.path` is always present and always absolute
const outputPath = compilation.getPath(
compilation.outputOptions.path || "",
);
const publicPath = options.publicPath
? compilation.getPath(options.publicPath)
: compilation.outputOptions.publicPath
? compilation.getPath(compilation.outputOptions.publicPath)
: "";
publicPaths.push({
outputPath,
publicPath,
assetsInfo: compilation.assetsInfo,
});
}
return publicPaths;
}
module.exports = getPaths;