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.6 to 1.1.1

54

index.js

@@ -8,3 +8,3 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");

chunks.forEach(chunk => {
if (chunk.attributes.src && chunk.attributes.src.includes("_head")) {
if ((chunk.attributes.src && chunk.attributes.src.includes("_head")) || chunk.attributes.href) {
headChunks.push(chunk);

@@ -19,2 +19,36 @@ } else {

function addAttributesToTag(tag, name, attributes) {
if (tag.attributes.src) {
const regex = new RegExp(`(\/${name}\\.)|(${name}\\.)`);
if (tag.attributes.src.match(regex)) {
tag.attributes = {...tag.attributes, ...attributes}
}
}
}
function handleChunksConfig(data, tags) {
if (data.plugin.options.chunksConfig) {
const asyncNames = data.plugin.options.chunksConfig.async;
const deferNames = data.plugin.options.chunksConfig.defer;
if (typeof asyncNames === "object" && typeof deferNames === "object") {
tags.forEach(tag => {
// add async/defer only on script tags.
if (!tag.attributes.href && tag.attributes.src) {
asyncNames.forEach(name => {
addAttributesToTag(tag, name, {async: true});
});
deferNames.forEach(name => {
addAttributesToTag(tag, name, {defer: true});
})
}
});
} else {
console.log("-------------------------------------");
console.error("Invalid value given to chunksConfig option");
console.log("-------------------------------------");
}
}
}
class HtmlWebpackInjectorPlugin {

@@ -28,6 +62,8 @@ apply(compiler) {

const ch = getHeadAndBodyChunks([...data.headTags, ...data.bodyTags]);
const tags = [...data.bodyTags, ...data.headTags];
handleChunksConfig(data, tags);
const chunks = getHeadAndBodyChunks(tags);
data.headTags = ch.headChunks;
data.bodyTags = ch.bodyChunks;
data.headTags = chunks.headChunks;
data.bodyTags = chunks.bodyChunks;

@@ -43,6 +79,8 @@ callback(null, data)

const ch = getHeadAndBodyChunks([...data.head, ...data.body]);
const tags = [...data.body, ...data.head];
handleChunksConfig(data, tags);
const chunks = getHeadAndBodyChunks(tags);
data.head = ch.headChunks;
data.body = ch.bodyChunks;
data.head = chunks.headChunks;
data.body = chunks.bodyChunks;
});

@@ -54,2 +92,2 @@ });

module.exports = HtmlWebpackInjectorPlugin;
module.exports = HtmlWebpackInjectorPlugin;

2

package.json
{
"name": "html-webpack-injector",
"version": "1.0.6",
"version": "1.1.1",
"description": "Helps to inject chunks to head and body via HtmlWebpackPlugin",

@@ -5,0 +5,0 @@ "main": "index.js",

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