From 5043ac0712c0a3fd16794aebacbdc4741d4379bd Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Thu, 7 May 2015 08:51:47 +0200 Subject: [PATCH] Update documentation --- README.md | 4 ++++ index.js | 10 +++++++--- package.json | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e45f80c..74af037 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,10 @@ Allowed values are as follows: - `title`: The title to use for the generated HTML document. - `filename`: The file to write the HTML to. Defaults to `index.html`. You can specify a subdirectory here too (eg: `assets/admin.html`). +- `template`: A html template (supports [blueimp templates](https://github.com/blueimp/JavaScript-Templates)). +- `templateContent`: A html string or a function returning the html (supports [blueimp templates](https://github.com/blueimp/JavaScript-Templates)). +- `inject`: Inject all assets into the given `template` or `templateContent`. +- `minify`: Set to true or pass a [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference) options object to minify the output. - `hash`: 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 1242c4b..630d964 100644 --- a/index.js +++ b/index.js @@ -104,20 +104,24 @@ HtmlWebpackPlugin.prototype.getTemplateContent = function(compilation, templateP */ HtmlWebpackPlugin.prototype.emitHtml = function(compilation, htmlTemplateContent, templateParams, outputFilename) { var html; + // blueimp-tmpl processing try { html = tmpl(htmlTemplateContent, templateParams); } catch(e) { return Promise.reject(new Error('HtmlWebpackPlugin: template error ' + e)); } + // Inject link and script elements into an existing html file if (this.options.inject) { html = this.injectAssetsIntoHtml(html, templateParams); } - if (templateParams.htmlWebpackPlugin.options.minify) { + // Minify the html output + if (this.options.minify) { var minify = require('html-minifier').minify; - var minify_options = templateParams.htmlWebpackPlugin.options.minify.constructor === Object ? templateParams.htmlWebpackPlugin.options.minify : {}; - html = minify(html, minify_options); + // If `options.minify` is set to true use the default minify options + var minifyOptions = _.isObject(this.options.minify) ? this.options.minify : {}; + html = minify(html, minifyOptions); } compilation.assets[outputFilename] = { diff --git a/package.json b/package.json index 7a2ee93..02cb720 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "html-webpack-plugin", - "version": "1.3.0", + "version": "1.4.0", "description": "Simplifies creation of HTML files to serve your webpack bundles", "main": "index.js", "files": [