Skip to content

Commit e8e5757

Browse files
author
Anton Dubrouski
committed
feat: publicPath output
1 parent 8c1abc9 commit e8e5757

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

lib/Server.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -2868,7 +2868,10 @@ class Server {
28682868
return msg;
28692869
},
28702870
};
2871-
const useColor = getColorsOption(this.getCompilerOptions());
2871+
2872+
const compilerOptions = this.getCompilerOptions();
2873+
2874+
const useColor = getColorsOption(compilerOptions);
28722875

28732876
const server = /** @type {S} */ (this.server);
28742877

@@ -2883,8 +2886,19 @@ class Server {
28832886
* @param {string} newHostname
28842887
* @returns {string}
28852888
*/
2886-
const prettyPrintURL = (newHostname) =>
2887-
url.format({ protocol, hostname: newHostname, port, pathname: "/" });
2889+
const prettyPrintURL = (newHostname) => {
2890+
const publicPath = compilerOptions.output.publicPath;
2891+
2892+
return url.format({
2893+
protocol,
2894+
hostname: newHostname,
2895+
port,
2896+
pathname:
2897+
typeof publicPath === "function" || publicPath === "auto"
2898+
? "/"
2899+
: publicPath,
2900+
});
2901+
};
28882902

28892903
let host;
28902904
let localhost;

test/cli/__snapshots__/basic.test.js.snap.webpack5

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ exports[`basic basic should accept the promise function of webpack.config.js: st
88
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
99
`;
1010

11+
exports[`basic basic should respect output.publicPath config option in URL's output: stderr 1`] = `
12+
"<i> [webpack-dev-server] Project is running at:
13+
<i> Loopback: http://localhost:<port>/, http://<ip-v4>:<port>/, http://[<ip-v6>]:<port>/
14+
<i> [webpack-dev-server] On Your Network (IPv4): http://<ip-v4>:<port>/foo/
15+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
16+
`;
17+
1118
exports[`basic basic should work using "--host localhost --port <port>": stderr 1`] = `
1219
"<i> [webpack-dev-server] Project is running at:
1320
<i> Loopback: http://localhost:<port>/, http://<ip-v4>:<port>/, http://[<ip-v6>]:<port>/

test/cli/basic.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ describe("basic", () => {
5757
expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot("stderr");
5858
});
5959

60+
it("should respect output.publicPath config option in URL's output", async () => {
61+
const { exitCode, stderr } = await testBin([
62+
"--config",
63+
path.resolve(
64+
__dirname,
65+
"../fixtures/cli-output-public-path-config/webpack.config.js",
66+
),
67+
"--port",
68+
port,
69+
]);
70+
71+
expect(exitCode).toEqual(0);
72+
expect(normalizeStderr(stderr)).toMatchSnapshot("stderr");
73+
});
74+
6075
it("should work using multi compiler mode", async () => {
6176
const { exitCode, stderr } = await testBin([
6277
"--config",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"use strict";
2+
3+
console.log("i am foo!");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use strict";
2+
3+
const { join } = require("path");
4+
5+
module.exports = {
6+
mode: "development",
7+
entry: join(__dirname, "foo.js"),
8+
output: {
9+
publicPath: "/foo/",
10+
},
11+
};

0 commit comments

Comments
 (0)