Fix manifest option and add tests.
This commit is contained in:
parent
989a09f97a
commit
648fd72c22
|
|
@ -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.
|
||||
|
|
|
|||
8
index.js
8
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() {
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
})
|
||||
]
|
||||
}, ['<html manifest="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')
|
||||
})
|
||||
]
|
||||
}, ['<html lang="en" manifest="foo.appcache">'], null, done);
|
||||
});
|
||||
|
||||
it('shows an error when a template fails to load', function(done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"name": "HtmlWebpackPlugin"
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="en" manifest="foo.appcache">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Example Plain file</title>
|
||||
|
|
@ -7,4 +7,4 @@
|
|||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in New Issue