Skip to content

Commit

Permalink
feat: add distPublicPath option to server config
Browse files Browse the repository at this point in the history
Now you can override system hard coded URL to the dist directory
during development time. It has no effect on the production build
where WordPress itself tells about directory URL.
  • Loading branch information
swashata committed Nov 14, 2018
1 parent 1d056ee commit 6f7773d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
8 changes: 7 additions & 1 deletion packages/scripts/src/config/CreateWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}/`;
}

/**
Expand Down
11 changes: 7 additions & 4 deletions packages/scripts/src/config/WebpackConfigHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/scripts/src/config/server.config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
};

0 comments on commit 6f7773d

Please sign in to comment.