diff --git a/lib/html-tags.js b/lib/html-tags.js
index 5e727a92..3dd3df92 100644
--- a/lib/html-tags.js
+++ b/lib/html-tags.js
@@ -25,12 +25,12 @@ const voidTags = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'k
* A tag element according to the htmlWebpackPlugin object notation
*
* @param xhtml {boolean}
- * Wether the generated html should add closing slashes to be xhtml compliant
+ * Whether the generated html should add closing slashes to be xhtml compliant
*/
function htmlTagObjectToString (tagDefinition, xhtml) {
const attributes = Object.keys(tagDefinition.attributes || {})
.filter(function (attributeName) {
- return tagDefinition.attributes[attributeName] !== false;
+ return tagDefinition.attributes[attributeName] === '' || tagDefinition.attributes[attributeName];
})
.map(function (attributeName) {
if (tagDefinition.attributes[attributeName] === true) {
@@ -49,13 +49,13 @@ function htmlTagObjectToString (tagDefinition, xhtml) {
* @param {string} tagName
* the name of the tag e.g. 'div'
*
- * @param {{[attributeName: string]: string|boolean}} [attributes]
+ * @param {{[attributeName: string]: string|boolean|null|undefined}} [attributes]
* tag attributes e.g. `{ 'class': 'example', disabled: true }`
*
* @param {string} [innerHTML]
*
- * @param {{[attributeName: string]: string|boolean}} [meta]
- * meta information about the tag e.g. `{ 'pluhin': 'html-webpack-plugin' }`
+ * @param {{[attributeName: string]: string|boolean|null|undefined}} [meta]
+ * meta information about the tag e.g. `{ 'plugin': 'html-webpack-plugin' }`
*
* @returns {HtmlTagObject}
*/
diff --git a/spec/basic.spec.js b/spec/basic.spec.js
index 13fd6a55..3cb646d5 100644
--- a/spec/basic.spec.js
+++ b/spec/basic.spec.js
@@ -1232,6 +1232,74 @@ describe('HtmlWebpackPlugin', () => {
null, done, false, false);
});
+ it('allows events to remove an attribute by setting it to null', done => {
+ const examplePlugin = {
+ apply: function (compiler) {
+ compiler.hooks.compilation.tap('HtmlWebpackPlugin', compilation => {
+ HtmlWebpackPlugin.getHooks(compilation).alterAssetTags.tapAsync('HtmlWebpackPluginTest', (pluginArgs, callback) => {
+ pluginArgs.assetTags.scripts = pluginArgs.assetTags.scripts.map(tag => {
+ if (tag.tagName === 'script') {
+ tag.attributes.async = null;
+ }
+ return tag;
+ });
+ callback(null, pluginArgs);
+ });
+ });
+ }
+ };
+ testHtmlPlugin({
+ mode: 'production',
+ entry: {
+ app: path.join(__dirname, 'fixtures/index.js')
+ },
+ output: {
+ path: OUTPUT_DIR,
+ filename: '[name]_bundle.js'
+ },
+ plugins: [
+ new HtmlWebpackPlugin(),
+ examplePlugin
+ ]
+ },
+ [/