Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html-webpack-injector

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-webpack-injector - npm Package Compare versions

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"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc