diff --git a/README.md b/README.md index f9c3f4a..891a098 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ Allowed values are as follows: - `template`: Path to the template. Supports loaders e.g. `html!./index.html`. - `inject`: `true | 'head' | 'body' | false` Inject all assets into the given `template` or `templateContent` - When passing `true` or `'body'` all javascript resources will be placed at the bottom of the body element. `'head'` will place the scripts in the head element. - `favicon`: Adds the given favicon path to the output html. +- `manifest`: Adds the given manifest path to the output html. - `minify`: `{...} | false` Pass a [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference) options object to minify the output. - `hash`: `true | false` if `true` then append a unique webpack compilation hash to all included scripts and css files. This is useful for cache busting. diff --git a/index.js b/index.js index eaa47ac..23dcad2 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,7 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) { // Get assets var assets = self.htmlWebpackPluginAssets(compilation, chunks); Promise.resolve() - // Favicon + // Favicon and manifest .then(function() { if (self.options.favicon) { return self.addFileToAssets(self.options.favicon, compilation) @@ -61,6 +61,12 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) { assets.favicon = faviconBasename; }); } + if (self.options.manifest) { + return self.addFileToAssets(self.options.manifest, compilation) + .then(function(manifestBasename){ + assets.manifest = manifestBasename; + }); + } }) // Wait for the compilation to finish .then(function() { diff --git a/spec/HtmlWebpackPluginSpec.js b/spec/HtmlWebpackPluginSpec.js index 85e68ab..d79334c 100644 --- a/spec/HtmlWebpackPluginSpec.js +++ b/spec/HtmlWebpackPluginSpec.js @@ -553,6 +553,37 @@ describe('HtmlWebpackPlugin', function() { }, ['Error: HtmlWebpackPlugin: could not load file'], null, done, true); }); + it('adds a manifest', function(done) { + testHtmlPlugin({ + entry: path.join(__dirname, 'fixtures/index.js'), + output: { + path: OUTPUT_DIR, + filename: 'index_bundle.js' + }, + plugins: [ + new HtmlWebpackPlugin({ + manifest: path.join(__dirname, 'fixtures/manifest.json') + }) + ] + }, [''], null, done); + }); + + it('does not add a manifest if already present', function(done) { + testHtmlPlugin({ + entry: path.join(__dirname, 'fixtures/index.js'), + output: { + path: OUTPUT_DIR, + filename: 'index_bundle.js' + }, + plugins: [ + new HtmlWebpackPlugin({ + template: path.join(__dirname, 'fixtures/plain.html'), + manifest: path.join(__dirname, 'fixtures/manifest.json') + }) + ] + }, [''], null, done); + }); + it('shows an error when a template fails to load', function(done) { testHtmlPlugin({ entry: path.join(__dirname, 'fixtures/index.js'), diff --git a/spec/fixtures/manifest.json b/spec/fixtures/manifest.json new file mode 100644 index 0000000..fd3e289 --- /dev/null +++ b/spec/fixtures/manifest.json @@ -0,0 +1,3 @@ +{ + "name": "HtmlWebpackPlugin" +} diff --git a/spec/fixtures/plain.html b/spec/fixtures/plain.html index 7f2ea29..6eba5ca 100644 --- a/spec/fixtures/plain.html +++ b/spec/fixtures/plain.html @@ -1,5 +1,5 @@ - + Example Plain file @@ -7,4 +7,4 @@ - \ No newline at end of file +