Skip to content

Commit e206a12

Browse files
robertfauskweaverryan
authored andcommitted
fix issue in generated public path of manifest.json
- when using devServer and absolute URL for publicPath - also add test case
1 parent eb5565b commit e206a12

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/WebpackConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ class WebpackConfig {
131131
* @returns {string}
132132
*/
133133
getRealPublicPath() {
134-
// if we're using webpack-dev-server, use it & add the publicPath
135-
if (this.useDevServer()) {
134+
// if we're using webpack-dev-server and have no absolute url, use it & add the publicPath
135+
if (this.useDevServer() && !this.publicPath.includes('://')) {
136136
// avoid 2 middle slashes
137137
return this.runtimeConfig.devServerUrl.replace(/\/$/,'') + this.publicPath;
138138
}

test/config-generator.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,23 @@ describe('The config-generator function', () => {
375375
expect(actualConfig.devServer).to.be.undefined;
376376
});
377377

378+
it('devServer and an absolute URL as publicPath', () => {
379+
const config = createConfig();
380+
config.runtimeConfig.useDevServer = true;
381+
config.runtimeConfig.devServerUrl = 'http://localhost:8080/';
382+
config.outputPath = isWindows ? 'C:\\tmp\\public' : '/tmp/public';
383+
config.setManifestKeyPrefix('public');
384+
config.setPublicPath('https://cdn.example.com');
385+
config.addEntry('main', './main');
386+
387+
const actualConfig = configGenerator(config);
388+
expect(actualConfig.output.publicPath).to.equal('https://cdn.example.com/');
389+
expect(actualConfig.devServer).to.not.be.undefined;
390+
391+
const manifestPlugin = findPlugin(ManifestPlugin, actualConfig.plugins);
392+
expect(manifestPlugin.opts.publicPath).to.equal('https://cdn.example.com/');
393+
});
394+
378395
it('devServer no hot mode', () => {
379396
const config = createConfig();
380397
config.runtimeConfig.useDevServer = true;

0 commit comments

Comments
 (0)