Skip to content

Commit 07cce1d

Browse files
authored
feat: override publicPath setting. (#230)
* Allow user to override publicPath setting. This allows users to use Webpack's `auto` option for publicPath and still set a public path for the dev server. * updating docs and tests * cleanup logic to allow empty string as publicPath
1 parent 6826e9a commit 07cce1d

11 files changed

Lines changed: 15932 additions & 473 deletions

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ If [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), the modul
230230

231231
If a value of `'minimal'` is set, the progress indicator will render as a small, colored bar at the top of the window. This can be useful when the default fancy progress indicator interferes with elements in the page.
232232

233+
### `publicPath`
234+
Type: `String`<br>
235+
Default: `webpack.output.publicPath`
236+
237+
Sets the publicPath that the server should use to serve assets. You probably only need to set this explicitly if you are using [Webpack's `auto` feature](https://webpack.js.org/guides/public-path/#automatic-publicpath) for public path detection.
238+
233239
### `ramdisk`
234240
Type: `boolean | Object`<br>
235241
Default: `false`<br>

lib/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const defaults = {
3838
open: false,
3939
port: 55555,
4040
progress: true,
41+
publicPath: null,
4142
ramdisk: false,
4243
secure: false,
4344
static: null,
@@ -186,7 +187,10 @@ class WebpackPluginServe extends EventEmitter {
186187
}
187188

188189
// check static paths for publicPath. #100
189-
const { publicPath } = compiler.options.output;
190+
const publicPath =
191+
this.options.publicPath === null
192+
? compiler.options.output.publicPath
193+
: this.options.publicPath;
190194
if (publicPath) {
191195
let foundPath = false;
192196
for (const path of this.options.static) {
@@ -200,7 +204,7 @@ class WebpackPluginServe extends EventEmitter {
200204
/* istanbul ignore next */
201205
if (!foundPath) {
202206
this.log.warn(
203-
chalk`{bold {yellow Warning}} The value of {yellow \`output.publicPath\`} was not found on the filesystem in any static paths specified\n`
207+
chalk`{bold {yellow Warning}} The value of {yellow \`publicPath\`} was not found on the filesystem in any static paths specified\n`
204208
);
205209
}
206210
}

lib/validate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module.exports = {
5252
open: union([boolean(), type({})]),
5353
port: union([max(integer(), 65535), promise]),
5454
progress: union([boolean(), literal('minimal')]),
55+
publicPath: nullable(string()),
5556
ramdisk: union([boolean(), type({})]),
5657
secure: never(),
5758
static: nullable(

0 commit comments

Comments
 (0)