diff --git a/index.js b/index.js
index f59d91b..d0fa09d 100644
--- a/index.js
+++ b/index.js
@@ -93,7 +93,7 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) {
if (self.options.favicon) {
return self.addFileToAssets(self.options.favicon, compilation)
.then(function (faviconBasename) {
- var publicPath = compilation.options.output.publicPath || '';
+ var publicPath = compilation.mainTemplate.getPublicPath({hash: compilation.hash}) || '';
if (publicPath && publicPath.substr(-1) !== '/') {
publicPath += '/';
}
diff --git a/spec/BasicSpec.js b/spec/BasicSpec.js
index 05ce988..1f6289f 100644
--- a/spec/BasicSpec.js
+++ b/spec/BasicSpec.js
@@ -1007,6 +1007,22 @@ describe('HtmlWebpackPlugin', function () {
}, [//], null, done);
});
+ it('adds a favicon with a publichPath set to [hash]/ and replaces the hash', function (done) {
+ testHtmlPlugin({
+ entry: path.join(__dirname, 'fixtures/index.js'),
+ output: {
+ path: OUTPUT_DIR,
+ publicPath: '/[hash]/',
+ 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'),