Skip to content

Commit

Permalink
feat: allow skipping specific instances of html-webpack-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocodutra authored and jantimon committed Aug 14, 2019
1 parent 90d2584 commit d554946
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ In combination with [html-webpack-plugin](https://github.com/jantimon/html-webpa

> https://github.com/jantimon/favicons-webpack-plugin/blob/master/test/fixtures/expected/html
HTML injection is skipped for a particular `html-webpack-plugin` if either `inject` or `favicons`
properties are set to `false` in its configuration object.

## Advanced Usage

```javascript
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ 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) => {
htmlPluginData.html = htmlPluginData.html.replace(/(<\/head>)/i, result + '$&');
if (htmlPluginData.plugin.options.inject && htmlPluginData.plugin.options.favicons !== false) {
htmlPluginData.html = htmlPluginData.html.replace(/(<\/head>)/i, result + '$&');
}
return callback(null, htmlPluginData);
});
}
Expand Down
32 changes: 32 additions & 0 deletions test/nohtml.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,36 @@ test('should allow disabling html injection', async t => {
t.deepEqual(await compare(dist, path.resolve(expected, 'nohtml')), []);
});

test('should respect HtmlWebpackPlugin@inject flag', 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}),
],
});

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

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

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

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

0 comments on commit d554946

Please sign in to comment.