Skip to content

Commit bd40246

Browse files
authored
Merge pull request #18 from arundo/inline-manifest-option
Inline manifest option
2 parents 05d5890 + f19f911 commit bd40246

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ module.exports = {
2727
plugins: [
2828
new ChunkManifestPlugin({
2929
filename: "manifest.json",
30-
manifestVariable: "webpackManifest"
30+
manifestVariable: "webpackManifest",
31+
inlineManifest: false
3132
})
3233
]
3334
};
@@ -42,3 +43,15 @@ Where the manifest will be exported to on bundle compilation. This will be relat
4243
#### `manifestVariable`
4344

4445
What JS variable on the client webpack should refer to when requiring chunks. Default = `"webpackManifest"`
46+
47+
#### `inlineManifest`
48+
49+
Whether or not to write the manifest output into the [html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin). Default = `false`
50+
51+
```html
52+
// index.ejs
53+
<body>
54+
<!-- app -->
55+
<%= htmlWebpackPlugin.files.webpackManifest %>
56+
</body>
57+
```

lib/ChunkManifestPlugin.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@ function ChunkManifestPlugin(options) {
44
options = options || {};
55
this.manifestFilename = options.filename || "manifest.json";
66
this.manifestVariable = options.manifestVariable || "webpackManifest";
7+
this.inlineManifest = options.inlineManifest || false;
78
}
89
module.exports = ChunkManifestPlugin;
910

1011
ChunkManifestPlugin.prototype.constructor = ChunkManifestPlugin;
1112
ChunkManifestPlugin.prototype.apply = function(compiler) {
1213
var manifestFilename = this.manifestFilename;
1314
var manifestVariable = this.manifestVariable;
15+
var inlineManifest = this.inlineManifest;
1416
var oldChunkFilename;
17+
var chunkManifest;
1518

1619
compiler.plugin("this-compilation", function(compilation) {
1720
var mainTemplate = compilation.mainTemplate;
1821
mainTemplate.plugin("require-ensure", function(_, chunk, hash) {
1922
var filename = this.outputOptions.chunkFilename || this.outputOptions.filename;
20-
var chunkManifest;
2123

2224
if (filename) {
2325
chunkManifest = [chunk].reduce(function registerChunk(manifest, c) {
@@ -52,5 +54,12 @@ ChunkManifestPlugin.prototype.apply = function(compiler) {
5254
return _.replace("\"__CHUNK_MANIFEST__\"",
5355
"window[\"" + manifestVariable + "\"][" + chunkIdVar + "]");
5456
});
57+
58+
if (inlineManifest){
59+
compilation.plugin("html-webpack-plugin-before-html-generation", function (data, callback) {
60+
var manifestHtml = "<script>window." + manifestVariable + "=" + JSON.stringify(chunkManifest) + "</script>";
61+
callback(null, data.assets[manifestVariable] = manifestHtml);
62+
});
63+
}
5564
});
5665
};

0 commit comments

Comments
 (0)