diff --git a/packages/scripts/src/config/CreateWebpackConfig.ts b/packages/scripts/src/config/CreateWebpackConfig.ts index 6acea9755..f87014b7b 100644 --- a/packages/scripts/src/config/CreateWebpackConfig.ts +++ b/packages/scripts/src/config/CreateWebpackConfig.ts @@ -52,7 +52,13 @@ export class CreateWebpackConfig { // Also figure out the publicPath beforehand, because we do need it const { slug, outputPath, type } = this.projectConfig; - this.publicPath = `/wp-content/${type}s/${slug}/${outputPath}/`; + // The public is generated automatically considering + // the dev server is installed at root, and wp-content, themes, plugins + // directories are all default. + // But one can pass distPublicPath from serverConfig to override it. + this.publicPath = + this.serverConfig.distPublicPath || + `/wp-content/${type}s/${slug}/${outputPath}/`; } /** diff --git a/packages/scripts/src/config/WebpackConfigHelper.ts b/packages/scripts/src/config/WebpackConfigHelper.ts index 920b7024e..023ee5f74 100644 --- a/packages/scripts/src/config/WebpackConfigHelper.ts +++ b/packages/scripts/src/config/WebpackConfigHelper.ts @@ -217,10 +217,13 @@ export class WebpackConfigHelper { }; // Add the publicPath if it is in devMode if (this.isDev) { - // We are proxying stuff here. So I guess, we can safely assume - // That URL of the proxied server starts from root? - // Maybe we can have a `prefix` in Config, but let's not do that - // right now. + // This is calculated by CreateWebpackConfig + // taking into consideration user's own value. + // So, if WordPress defaults are changed, then + // depending on wpackio.server.js, it will still + // point to the right location. It only makes + // dynamic import and some on-demand split-chunk + // work. output.publicPath = this.config.publicPathUrl; } diff --git a/packages/scripts/src/config/server.config.default.ts b/packages/scripts/src/config/server.config.default.ts index 741f23972..4c93abad8 100644 --- a/packages/scripts/src/config/server.config.default.ts +++ b/packages/scripts/src/config/server.config.default.ts @@ -10,6 +10,7 @@ export interface ServerConfig { ghostMode: browserSync.Options['ghostMode']; // tslint:disable-next-line:no-any bsOverride?: { [x: string]: any }; + distPublicPath?: string; } export const serverConfigDefault: ServerConfig = { @@ -44,4 +45,7 @@ export const serverConfigDefault: ServerConfig = { scroll: true, forms: true, }, + // Override system calculated public path of the `dist` directory + // This must have forward slash, otherwise it will not work. + distPublicPath: undefined, };