From ca694acc1c01f9430ca4b42458bce74b81c4b357 Mon Sep 17 00:00:00 2001 From: stoccc <> Date: Tue, 13 Feb 2018 11:30:20 +0100 Subject: [PATCH 1/3] These changes allow empty public path in webpack.config.js Provided a functional test. See https://github.com/symfony/webpack-encore/issues/26#issuecomment-362560685 --- lib/WebpackConfig.js | 8 +++++--- test/functional.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) 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..21beb84f 100644 --- a/test/functional.js +++ b/test/functional.js @@ -227,6 +227,36 @@ 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( + // the webroot will not include the public/build part + path.join(config.getContext(), ''), + [ + convertToManifestPath('build/main.js', config) + ], + (browser) => { + webpackAssert.assertResourcesLoadedCorrectly(browser, [ + 'http://127.0.0.1:8080/public/build/0.js', + 'http://127.0.0.1:8080/public/build/main.js' + ]); + + done(); + } + ); + }); + }); + it('Empty manifestKeyPrefix is allowed', (done) => { const config = createWebpackConfig('build', 'dev'); config.addEntry('main', './js/code_splitting'); From 3bd6335879214f2aa2940dece727542b889edafc Mon Sep 17 00:00:00 2001 From: stoccc <> Date: Tue, 13 Feb 2018 11:54:43 +0100 Subject: [PATCH 2/3] Fixed document root in functional test --- test/functional.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/functional.js b/test/functional.js index 21beb84f..d6f4b3fe 100644 --- a/test/functional.js +++ b/test/functional.js @@ -240,8 +240,7 @@ describe('Functional tests using webpack', function() { ); testSetup.requestTestPage( - // the webroot will not include the public/build part - path.join(config.getContext(), ''), + path.join(config.getContext(), 'public'), [ convertToManifestPath('build/main.js', config) ], From 9a0b38235d0302f24f279f57d92c9072a2a73f35 Mon Sep 17 00:00:00 2001 From: stoccc <> Date: Tue, 13 Feb 2018 11:59:28 +0100 Subject: [PATCH 3/3] Fix paths in functional tests --- test/functional.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional.js b/test/functional.js index d6f4b3fe..c6aa313b 100644 --- a/test/functional.js +++ b/test/functional.js @@ -246,8 +246,8 @@ describe('Functional tests using webpack', function() { ], (browser) => { webpackAssert.assertResourcesLoadedCorrectly(browser, [ - 'http://127.0.0.1:8080/public/build/0.js', - 'http://127.0.0.1:8080/public/build/main.js' + 'http://127.0.0.1:8080/build/0.js', + 'http://127.0.0.1:8080/build/main.js' ]); done();