diff --git a/README.md b/README.md
index 10eabfb..1a4984d 100644
--- a/README.md
+++ b/README.md
@@ -240,6 +240,7 @@ Events
To allow other plugins to alter the html this plugin executes the following events:
+ * `html-webpack-plugin-before-html-generation`
* `html-webpack-plugin-before-html-processing`
* `html-webpack-plugin-after-html-processing`
* `html-webpack-plugin-after-emit`
diff --git a/index.js b/index.js
index 1af1f30..7714d4e 100644
--- a/index.js
+++ b/index.js
@@ -96,9 +96,17 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) {
// and replace it with its content
return self.evaluateCompilationResult(compilation, compiledTemplate);
})
+ // Allow plugins to make changes to the assets before invoking the template
+ // This only makes sense to use if `inject` is `false`
+ .then(function (compilationResult) {
+ return applyPluginsAsyncWaterfall('html-webpack-plugin-before-html-generation', {assets: assets, plugin: self})
+ .then(function () {
+ return compilationResult;
+ });
+ })
// Execute the template
.then(function (compilationResult) {
- // If the loader result is a function execute it to retreive the html
+ // If the loader result is a function execute it to retrieve the html
// otherwise use the returned html
return typeof compilationResult !== 'function'
? compilationResult
diff --git a/spec/HtmlWebpackPluginSpec.js b/spec/HtmlWebpackPluginSpec.js
index a52234f..bd567f8 100644
--- a/spec/HtmlWebpackPluginSpec.js
+++ b/spec/HtmlWebpackPluginSpec.js
@@ -772,6 +772,40 @@ describe('HtmlWebpackPlugin', function () {
});
});
+ it('allows to modify the html during html-webpack-plugin-before-html-generation event', function (done) {
+ var eventFired = false;
+ var examplePlugin = {
+ apply: function (compiler) {
+ compiler.plugin('compilation', function (compilation) {
+ compilation.plugin('html-webpack-plugin-before-html-generation', function (object, callback) {
+ eventFired = true;
+ object.assets.js.push('funky-script.js');
+ callback();
+ });
+ });
+ }
+ };
+ testHtmlPlugin({
+ entry: {
+ app: path.join(__dirname, 'fixtures/index.js')
+ },
+ output: {
+ path: OUTPUT_DIR,
+ filename: '[name]_bundle.js'
+ },
+ plugins: [
+ new HtmlWebpackPlugin({
+ inject: false,
+ template: 'underscore-template-loader!' + path.join(__dirname, 'fixtures/custom_file.html')
+ }),
+ examplePlugin
+ ]
+ }, ['
+ <% } %>
+
+