html-webpack-injector
Advanced tools
Comparing version 1.0.5 to 1.0.6
61
index.js
const HtmlWebpackPlugin = require("html-webpack-plugin"); | ||
function getHeadAndBodyChunks(chunks) { | ||
const headChunks = []; | ||
const bodyChunks = []; | ||
chunks.forEach(chunk => { | ||
if (chunk.attributes.src && chunk.attributes.src.includes("_head")) { | ||
headChunks.push(chunk); | ||
} else { | ||
bodyChunks.push(chunk); | ||
} | ||
}); | ||
return {headChunks, bodyChunks}; | ||
} | ||
class HtmlWebpackInjectorPlugin { | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap('HtmlWebpackInjectorPlugin', (compilation) => { | ||
HtmlWebpackPlugin.getHooks(compilation).alterAssetTagGroups.tapAsync( | ||
'HtmlWebpackInjectorPlugin', | ||
(data, callback) => { | ||
const chunks = [...data.headTags, ...data.bodyTags]; | ||
const headChunks = []; | ||
const bodyChunks = []; | ||
apply(compiler) { | ||
// HtmlWebpackPlugin version 4.0.0-beta.5 | ||
if (HtmlWebpackPlugin.getHooks) { | ||
compiler.hooks.compilation.tap('HtmlWebpackInjectorPlugin', (compilation) => { | ||
HtmlWebpackPlugin.getHooks(compilation).alterAssetTagGroups.tapAsync( | ||
'HtmlWebpackInjectorPlugin', (data, callback) => { | ||
chunks.forEach(chunk => { | ||
if (chunk.attributes.src && chunk.attributes.src.includes("_head")) { | ||
headChunks.push(chunk); | ||
} else { | ||
bodyChunks.push(chunk); | ||
} | ||
}); | ||
const ch = getHeadAndBodyChunks([...data.headTags, ...data.bodyTags]); | ||
data.headTags = headChunks; | ||
data.bodyTags = bodyChunks; | ||
data.headTags = ch.headChunks; | ||
data.bodyTags = ch.bodyChunks; | ||
callback(null, data) | ||
} | ||
) | ||
}) | ||
callback(null, data) | ||
} | ||
) | ||
}); | ||
} else { | ||
// HtmlWebpackPlugin version 3.2.0 | ||
compiler.plugin("compilation", compilation => { | ||
compilation.plugin("html-webpack-plugin-alter-asset-tags", data => { | ||
const ch = getHeadAndBodyChunks([...data.head, ...data.body]); | ||
data.head = ch.headChunks; | ||
data.body = ch.bodyChunks; | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
module.exports = HtmlWebpackInjectorPlugin; |
{ | ||
"name": "html-webpack-injector", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Helps to inject chunks to head and body via HtmlWebpackPlugin", | ||
@@ -16,6 +16,3 @@ "main": "index.js", | ||
"author": "Archit garg <thearchitgargg@gmail.com> (https://github.com/thearchitgarg)", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"html-webpack-plugin": "4.0.0-beta.5" | ||
} | ||
"license": "ISC" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19802
0
39