Skip to content

Commit

Permalink
feat: add inject force option to overrule the html-webpack-plugin fav…
Browse files Browse the repository at this point in the history
…icon option
  • Loading branch information
aldarund authored and jantimon committed Aug 14, 2019
1 parent 3dbcd12 commit 73b51a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ module.exports = class FaviconsWebpackPlugin {
if (this.options.inject) {
// Hook into the html-webpack-plugin processing and add the html
tap(compilation, 'html-webpack-plugin-before-html-processing', 'FaviconsWebpackPlugin', (htmlPluginData, callback) => {
if (htmlPluginData.plugin.options.inject && htmlPluginData.plugin.options.favicons !== false) {
const htmlPluginDataInject = htmlPluginData.plugin.options.inject && htmlPluginData.plugin.options.favicons !== false;
if ( htmlPluginDataInject || this.options.inject === 'force') {
htmlPluginData.html = htmlPluginData.html.replace(/(<\/head>)/i, result + '$&');
}
return callback(null, htmlPluginData);
Expand Down
16 changes: 16 additions & 0 deletions test/html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,20 @@ test('should work together with the html-webpack-plugin', async t => {
t.deepEqual(await compare(dist, path.resolve(expected, 'html')), []);
});

test('should inject html despite HtmlWebpackPlugin@inject flag with inject force', async t => {
const dist = path.join(t.context.root, 'dist');
await generate({
context: t.context.root,
output: {
path: dist,
},
plugins: [
new HtmlWebpackPlugin({inject: false}),
new WebappWebpackPlugin({logo, inject: 'force'}),
],
});

t.deepEqual(await compare(dist, path.resolve(expected, 'html')), []);
});

test.afterEach(t => fs.remove(t.context.root));

0 comments on commit 73b51a1

Please # to comment.