replace [hash] in publicPath of favicon (#441)

This commit is contained in:
christoph peter 2016-09-26 12:29:30 +02:00 committed by Jan Nicklas
parent 03758f46cc
commit 9757d3df30
2 changed files with 17 additions and 1 deletions

View File

@ -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 += '/';
}

View File

@ -1007,6 +1007,22 @@ describe('HtmlWebpackPlugin', function () {
}, [/<link rel="shortcut icon" href="\/some\/+[^"]+\.ico">/], 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')
})
]
}, [/<link rel="shortcut icon" href="\/[a-z0-9]{20}\/favicon\.ico">/], null, done);
});
it('adds a favicon with inject enabled', function (done) {
testHtmlPlugin({
entry: path.join(__dirname, 'fixtures/index.js'),