diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 68545720..bff8d86b 100644 --- a/lib/WebpackConfig.js +++ b/lib/WebpackConfig.js @@ -134,9 +134,11 @@ class WebpackConfig { logger.warning('The value passed to setPublicPath() should *usually* start with "/" or be a full URL (http://...). If you\'re not sure, then you should probably change your public path and make this message disappear.'); } - // guarantee a single trailing slash - publicPath = publicPath.replace(/\/$/,''); - publicPath = publicPath + '/'; + if (publicPath !== '') { + // guarantee a single trailing slash + publicPath = publicPath.replace(/\/$/, ''); + publicPath = publicPath + '/'; + } this.publicPath = publicPath; } diff --git a/test/functional.js b/test/functional.js index 651e7d72..c6aa313b 100644 --- a/test/functional.js +++ b/test/functional.js @@ -227,6 +227,35 @@ describe('Functional tests using webpack', function() { }); }); + it('Deploying to an unknown (at compile-time) subdirectory is no problem', (done) => { + const config = createWebpackConfig('public/build', 'dev'); + config.addEntry('main', './js/code_splitting'); + config.setPublicPath(''); + config.setManifestKeyPrefix('build/'); + + testSetup.runWebpack(config, (webpackAssert) => { + webpackAssert.assertManifestPath( + 'build/main.js', + 'build/main.js' + ); + + testSetup.requestTestPage( + path.join(config.getContext(), 'public'), + [ + convertToManifestPath('build/main.js', config) + ], + (browser) => { + webpackAssert.assertResourcesLoadedCorrectly(browser, [ + 'http://127.0.0.1:8080/build/0.js', + 'http://127.0.0.1:8080/build/main.js' + ]); + + done(); + } + ); + }); + }); + it('Empty manifestKeyPrefix is allowed', (done) => { const config = createWebpackConfig('build', 'dev'); config.addEntry('main', './js/code_splitting');