Skip to content

Commit

Permalink
fix: respect output.publicPath for serve
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 29, 2020
1 parent cf4efb7 commit e3b7eae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/serve/src/startDevServer.ts
Expand Up @@ -68,6 +68,10 @@ export default async function startDevServer(compiler, cliOptions, logger): Prom
options.client = options.client || {};
options.client.port = options.client.port || options.port;
} else {
if (!options.publicPath && compiler.options.output && compiler.options.output.publicPath) {
options.publicPath = compiler.options.output.publicPath === 'auto' ? '/' : compiler.options.output.publicPath;
}

options.host = options.host || 'localhost';
options.port = options.port || 8080;
}
Expand Down
1 change: 1 addition & 0 deletions packages/serve/src/types.ts
Expand Up @@ -27,6 +27,7 @@ export type devServerOptionsType = {
static?: boolean | string | object | (string | object)[];
transportMode?: object | string;
useLocalIp?: boolean;
publicPath?: undefined;
};

type devServerClientOptions = {
Expand Down
12 changes: 10 additions & 2 deletions test/serve/basic/serve-basic.test.js
Expand Up @@ -141,8 +141,16 @@ describe('basic serve usage', () => {
expect(stdout.match(/HotModuleReplacementPlugin/g)).toHaveLength(1);
});

// TODO uncomment for webpack-dev-server@4
it.skip('should work with the "--output-public-path" option', async () => {
it('should work with the default "publicPath" option', async () => {
const { stderr, stdout } = await runServe(['serve'], __dirname);

expect(stderr).toBeFalsy();
expect(stdout).toContain('main.js');
expect(stdout).toContain('from /');
expect(stdout.match(/HotModuleReplacementPlugin/g)).toBeNull();
});

it('should work with the "--output-public-path" option', async () => {
const { stderr, stdout } = await runServe(['serve', '--output-public-path', '/my-public-path/'], __dirname);

expect(stderr).toBeFalsy();
Expand Down

0 comments on commit e3b7eae

Please sign in to comment.