diff --git a/index.js b/index.js index 62dd240..9932dd8 100644 --- a/index.js +++ b/index.js @@ -75,11 +75,11 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) { if (self.options.favicon) { return self.addFileToAssets(self.options.favicon, compilation) .then(function (faviconBasename) { - if (compilation.options.output.publicPath) { - assets.favicon = compilation.options.output.publicPath + faviconBasename; - } else { - assets.favicon = faviconBasename; + var publicPath = compilation.options.output.publicPath || ''; + if (publicPath && publicPath.substr(-1) !== '/') { + publicPath += '/'; } + assets.favicon = publicPath + faviconBasename; }); } }) diff --git a/package.json b/package.json index 025f87c..b09209a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "html-webpack-plugin", - "version": "2.8.2", + "version": "2.9.0", "description": "Simplifies creation of HTML files to serve your webpack bundles", "main": "index.js", "files": [ diff --git a/spec/HtmlWebpackPluginSpec.js b/spec/HtmlWebpackPluginSpec.js index ec65157..873952a 100644 --- a/spec/HtmlWebpackPluginSpec.js +++ b/spec/HtmlWebpackPluginSpec.js @@ -770,7 +770,7 @@ describe('HtmlWebpackPlugin', function () { }, [//], null, done); }); - it('adds a favicon with publicPath set', function (done) { + it('adds a favicon with publicPath set to /some/', function (done) { testHtmlPlugin({ entry: path.join(__dirname, 'fixtures/index.js'), output: { @@ -786,6 +786,22 @@ describe('HtmlWebpackPlugin', function () { }, [//], null, done); }); + it('adds a favicon with publicPath set to /some', function (done) { + testHtmlPlugin({ + entry: path.join(__dirname, 'fixtures/index.js'), + output: { + path: OUTPUT_DIR, + publicPath: '/some', + filename: 'index_bundle.js' + }, + plugins: [ + new HtmlWebpackPlugin({ + favicon: path.join(__dirname, 'fixtures/favicon.ico') + }) + ] + }, [//], null, done); + }); + it('adds a favicon with inject enabled', function (done) { testHtmlPlugin({ entry: path.join(__dirname, 'fixtures/index.js'),