diff --git a/README.md b/README.md index d79bd9e..b632e3c 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,8 @@ module.exports = { plugins: [ new ChunkManifestPlugin({ filename: "manifest.json", - manifestVariable: "webpackManifest" + manifestVariable: "webpackManifest", + inlineManifest: false }) ] }; @@ -42,3 +43,15 @@ Where the manifest will be exported to on bundle compilation. This will be relat #### `manifestVariable` What JS variable on the client webpack should refer to when requiring chunks. Default = `"webpackManifest"` + +#### `inlineManifest` + +Whether or not to write the manifest output into the [html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin). Default = `false` + +```html +// index.ejs + + + <%= htmlWebpackPlugin.files.webpackManifest %> + +``` \ No newline at end of file diff --git a/lib/ChunkManifestPlugin.js b/lib/ChunkManifestPlugin.js index d60164b..46d85ed 100644 --- a/lib/ChunkManifestPlugin.js +++ b/lib/ChunkManifestPlugin.js @@ -4,6 +4,7 @@ function ChunkManifestPlugin(options) { options = options || {}; this.manifestFilename = options.filename || "manifest.json"; this.manifestVariable = options.manifestVariable || "webpackManifest"; + this.inlineManifest = options.inlineManifest || false; } module.exports = ChunkManifestPlugin; @@ -11,13 +12,14 @@ ChunkManifestPlugin.prototype.constructor = ChunkManifestPlugin; ChunkManifestPlugin.prototype.apply = function(compiler) { var manifestFilename = this.manifestFilename; var manifestVariable = this.manifestVariable; + var inlineManifest = this.inlineManifest; var oldChunkFilename; + var chunkManifest; compiler.plugin("this-compilation", function(compilation) { var mainTemplate = compilation.mainTemplate; mainTemplate.plugin("require-ensure", function(_, chunk, hash) { var filename = this.outputOptions.chunkFilename || this.outputOptions.filename; - var chunkManifest; if (filename) { chunkManifest = [chunk].reduce(function registerChunk(manifest, c) { @@ -52,5 +54,12 @@ ChunkManifestPlugin.prototype.apply = function(compiler) { return _.replace("\"__CHUNK_MANIFEST__\"", "window[\"" + manifestVariable + "\"][" + chunkIdVar + "]"); }); + + if (inlineManifest){ + compilation.plugin("html-webpack-plugin-before-html-generation", function (data, callback) { + var manifestHtml = ""; + callback(null, data.assets[manifestVariable] = manifestHtml); + }); + } }); };