html-webpack-injector
Advanced tools
Comparing version 1.0.3 to 1.0.4
39
index.js
@@ -0,21 +1,28 @@ | ||
const HtmlWebpackPlugin = require("html-webpack-plugin"); | ||
class HtmlWebpackInjectorPlugin { | ||
apply(compiler) { | ||
compiler.plugin("compilation", compilation => { | ||
compilation.plugin("html-webpack-plugin-alter-asset-tags", object => { | ||
const chunks = [...object.head, ...object.body]; | ||
const headChunks = []; | ||
const bodyChunks = []; | ||
compiler.hooks.compilation.tap('HtmlWebpackInjectorPlugin', (compilation) => { | ||
HtmlWebpackPlugin.getHooks(compilation).alterAssetTagGroups.tapAsync( | ||
'HtmlWebpackInjectorPlugin', | ||
(data, callback) => { | ||
const chunks = [...data.headTags, ...data.bodyTags]; | ||
const headChunks = []; | ||
const bodyChunks = []; | ||
chunks.forEach(chunk => { | ||
if (chunk.attributes.src.includes("_head")) { | ||
headChunks.push(chunk); | ||
} else { | ||
bodyChunks.push(chunk); | ||
} | ||
}); | ||
chunks.forEach(chunk => { | ||
if (chunk.attributes.src.includes("_head")) { | ||
headChunks.push(chunk); | ||
} else { | ||
bodyChunks.push(chunk); | ||
} | ||
}); | ||
object.head = headChunks; | ||
object.body = bodyChunks; | ||
}); | ||
}); | ||
data.headTags = headChunks; | ||
data.bodyTags = bodyChunks; | ||
callback(null, data) | ||
} | ||
) | ||
}) | ||
} | ||
@@ -22,0 +29,0 @@ } |
{ | ||
"name": "html-webpack-injector", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Helps to inject chunks to head and body via HtmlWebpackPlugin", | ||
@@ -16,3 +16,6 @@ "main": "index.js", | ||
"author": "Archit garg <thearchitgargg@gmail.com> (https://github.com/thearchitgarg)", | ||
"license": "ISC" | ||
"license": "ISC", | ||
"devDependencies": { | ||
"html-webpack-plugin": "4.0.0-beta.5" | ||
} | ||
} |
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
19517
4
25
1