Skip to content

Commit 969b1fc

Browse files
committed
chore(options): move public path handling to api side
1 parent 390da6c commit 969b1fc

File tree

6 files changed

+240
-223
lines changed

6 files changed

+240
-223
lines changed

lib/utils/createConfig.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,6 @@ function createConfig(config, argv, { port }) {
4747
options.overlay = argv.overlay;
4848
}
4949

50-
options.devMiddleware = options.devMiddleware || {};
51-
52-
if (!options.devMiddleware.publicPath) {
53-
// eslint-disable-next-line
54-
options.devMiddleware.publicPath =
55-
(firstWpOpt.output && firstWpOpt.output.publicPath) || '';
56-
57-
if (
58-
!isAbsoluteUrl(String(options.devMiddleware.publicPath)) &&
59-
options.devMiddleware.publicPath[0] !== '/'
60-
) {
61-
options.devMiddleware.publicPath = `/${options.devMiddleware.publicPath}`;
62-
}
63-
}
64-
6550
if (!options.watchOptions && firstWpOpt.watchOptions) {
6651
options.watchOptions = firstWpOpt.watchOptions;
6752
}

lib/utils/normalizeOptions.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
'use strict';
22

3+
const isAbsoluteUrl = require('is-absolute-url');
4+
35
function normalizeOptions(compiler, options) {
6+
const firstWpOpt = compiler.compilers
7+
? compiler.compilers[0].options
8+
: compiler.options;
9+
410
// Setup default value
511
options.serveIndex =
612
typeof options.serveIndex !== 'undefined' ? options.serveIndex : true;
@@ -51,6 +57,20 @@ function normalizeOptions(compiler, options) {
5157
}`;
5258

5359
options.devMiddleware = options.devMiddleware || {};
60+
61+
// this was previously done in createConfig, but it should be done
62+
// here for CLI/API uniformity
63+
if (!options.devMiddleware.publicPath) {
64+
options.devMiddleware.publicPath =
65+
(firstWpOpt.output && firstWpOpt.output.publicPath) || '';
66+
67+
if (
68+
!isAbsoluteUrl(String(options.devMiddleware.publicPath)) &&
69+
options.devMiddleware.publicPath[0] !== '/'
70+
) {
71+
options.devMiddleware.publicPath = `/${options.devMiddleware.publicPath}`;
72+
}
73+
}
5474
}
5575

5676
module.exports = normalizeOptions;

0 commit comments

Comments
 (0)