Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jantimon/html-webpack-plugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 298635f4b3fb19fe920b1e0b982b61af0f31239d
Choose a base ref
...
head repository: jantimon/html-webpack-plugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5acac51da302451cca5b33f305d8d26c7cc2b87f
Choose a head ref

Commits on Dec 13, 2018

  1. chore: Release 4.0.0-beta.5

    jantimon committed Dec 13, 2018
    Copy the full SHA
    342c4e8 View commit details

Commits on Jan 11, 2019

  1. feat: Add typings to package.json

    See #1132
    wingrunr21 authored and jantimon committed Jan 11, 2019
    Copy the full SHA
    a524e8f View commit details

Commits on Feb 3, 2019

  1. Copy the full SHA
    56037a6 View commit details
  2. Copy the full SHA
    267e0e0 View commit details

Commits on Feb 16, 2019

  1. fix: Repair typings (#1166)

    jantimon authored Feb 16, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f4cb241 View commit details

Commits on Feb 17, 2019

  1. feat: Add support for <base> tag (#1160)

    atstp authored and jantimon committed Feb 17, 2019
    Copy the full SHA
    c5d4b86 View commit details
  2. Copy the full SHA
    d4eb1c7 View commit details

Commits on Mar 22, 2019

  1. fix: Use src/index.ejs by default if present (#1167)

    BREAKING CHANGE: Use src/index.ejs if no template option is set.
    jantimon authored Mar 22, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c27e5e4 View commit details

Commits on Mar 28, 2019

  1. Copy the full SHA
    2546551 View commit details

Commits on May 4, 2019

  1. chore: Update dependencies

    AviVahl authored and jantimon committed May 4, 2019
    Copy the full SHA
    38db64a View commit details

Commits on May 12, 2019

  1. added package for supporting issue #1158

    - #1158
    
    This package solves 
    #381, #818, #667, #624
    thearchitgarg authored and jantimon committed May 12, 2019
    Copy the full SHA
    8b9fb70 View commit details
  2. Added link and description for nomodule-plugin

    Created a new plugin to help limit executed file size.
    Adam Yost authored and jantimon committed May 12, 2019
    Copy the full SHA
    c02def8 View commit details
  3. renamed plugin

    Adam Yost authored and jantimon committed May 12, 2019
    Copy the full SHA
    7fa6aa8 View commit details
  4. Copy the full SHA
    17fbb30 View commit details

Commits on May 22, 2019

  1. Example README.md

    TroyTae authored and jantimon committed May 22, 2019
    Copy the full SHA
    895db29 View commit details

Commits on Jul 7, 2019

  1. Copy the full SHA
    a2a259a View commit details
  2. Fix migration.md

    Fix migration.md by adding `module.rules` rather than `module.loaders` and `pug-loader` rather than just `pug`.
    AhmedElaguab authored and jantimon committed Jul 7, 2019
    Copy the full SHA
    a18f809 View commit details

Commits on Jul 9, 2019

  1. Fix tiny typo

    Hey noticed a tiny typo in the comment.
    "as aminimalistic loader" => "as a minimalistic loader"
    adamsanderson authored and jantimon committed Jul 9, 2019
    Copy the full SHA
    0217b04 View commit details
  2. Update README.md

    hg-pyun authored and jantimon committed Jul 9, 2019
    Copy the full SHA
    d1bcd95 View commit details
  3. Copy the full SHA
    7f21910 View commit details
  4. chore: Adjust speed limit

    jantimon committed Jul 9, 2019
    Copy the full SHA
    5acac51 View commit details
71 changes: 53 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -77,6 +77,7 @@ The `html-webpack-plugin` provides [hooks](https://github.com/jantimon/html-webp
* [html-webpack-include-assets-plugin](https://github.com/jharris4/html-webpack-include-assets-plugin) for including lists of js or css file paths (such as those copied by the copy-webpack-plugin).
* [script-ext-html-webpack-plugin](https://github.com/numical/script-ext-html-webpack-plugin) to add `async`, `defer` or `module` attributes to your `<script>` elements, or even inline them
* [style-ext-html-webpack-plugin](https://github.com/numical/style-ext-html-webpack-plugin) to convert your `<link>`s to external stylesheets into `<style>` elements containing internal CSS
* [html-webpack-injector](https://github.com/thearchitgarg/html-webpack-injector) to inject chunks in `head` or `body` (different locations ) of same html document.
* [resource-hints-webpack-plugin](https://github.com/jantimon/resource-hints-webpack-plugin) to add resource hints for faster initial page loads using `<link rel='preload'>` and `<link rel='prefetch'>`
* [preload-webpack-plugin](https://github.com/GoogleChrome/preload-webpack-plugin) for automatically wiring up asynchronous (and other types) of JavaScript chunks using `<link rel='preload'>` helping with lazy-loading
* [link-media-html-webpack-plugin](https://github.com/yaycmyk/link-media-html-webpack-plugin) allows for injected stylesheet `<link />` tags to have their media attribute set automatically; useful for providing specific desktop/mobile/print etc. stylesheets that the browser will conditionally download
@@ -85,8 +86,8 @@ The `html-webpack-plugin` provides [hooks](https://github.com/jantimon/html-webp
* [html-webpack-exclude-empty-assets-plugin](https://github.com/KnisterPeter/html-webpack-exclude-empty-assets-plugin) removes empty assets from being added to the html. This fixes some problems with extract-text-plugin with webpack 4.
* [webpack-concat-plugin](https://github.com/hxlniada/webpack-concat-plugin) for concat and uglify files that needn't to be webpack bundles(for legacy files) and inject to html-webpack-plugin.
* [html-webpack-link-type-plugin](https://github.com/steadyapp/html-webpack-link-type-plugin) adds a configurable mimetype to resources injected as links (such as adding type="text/css" to external stylesheets) for compatibility with "strict mode".

* [csp-html-webpack-plugin](https://github.com/slackhq/csp-html-webpack-plugin) to add [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) meta tags to the HTML output
* [webpack-nomodule-plugin](https://github.com/swimmadude66/webpack-nomodule-plugin) allows you to add a `nomodule` attribute to specific injected scripts, which prevents the scripts from being loaded by newer browsers. Good for limiting loads of polyfills.


<h2 align="center">Usage</h2>
@@ -128,7 +129,7 @@ This will generate a file `dist/index.html` containing the following

If you have multiple `webpack` entry points, they will all be included with `script` tags in the generated HTML.

If you have any CSS assets in webpack's output (for example, CSS extracted with the [ExtractTextPlugin](https://github.com/webpack/extract-text-webpack-plugin))
If you have any CSS assets in webpack's output (for example, CSS extracted with the [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin))
then these will be included with `<link>` tags in the HTML head.

If you have plugins that make use of it, `html-webpack-plugin` should be ordered first before any of the integrated plugins.
@@ -140,21 +141,22 @@ Allowed values are as follows

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|**[`title`](#)**|`{String}`|`Webpack App`|The title to use for the generated HTML document|
|**[`filename`](#)**|`{String}`|`'index.html'`|The file to write the HTML to. Defaults to `index.html`. You can specify a subdirectory here too (eg: `assets/admin.html`)|
|**[`template`](#)**|`{String}`|``|`webpack` require path to the template. Please see the [docs](https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md) for details|
|**[`templateParameters`](#)**|`{Boolean\|Object\|Function}`|``| Allows to overwrite the parameters used in the template |
|**[`inject`](#)**|`{Boolean\|String}`|`true`|`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`](#)**|`{String}`|``|Adds the given favicon path to the output HTML|
|**[`meta`](#)**|`{Object}`|`{}`|Allows to inject `meta`-tags. E.g. `meta: {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`|
|**[`minify`](#)**|`{Boolean\|Object}`|`true` if `mode` is `'production'`, otherwise `false`|Controls if and in what ways the output should be minified. See [minification](#minification) below for more details.|
|**[`hash`](#)**|`{Boolean}`|`false`|If `true` then append a unique `webpack` compilation hash to all included scripts and CSS files. This is useful for cache busting|
|**[`cache`](#)**|`{Boolean}`|`true`|Emit the file only if it was changed|
|**[`showErrors`](#)**|`{Boolean}`|`true`|Errors details will be written into the HTML page|
|**[`chunks`](#)**|`{?}`|`?`|Allows you to add only some chunks (e.g only the unit-test chunk)|
|**`title`**|`{String}`|`Webpack App`|The title to use for the generated HTML document|
|**`filename`**|`{String}`|`'index.html'`|The file to write the HTML to. Defaults to `index.html`. You can specify a subdirectory here too (eg: `assets/admin.html`)|
|**`template`**|`{String}`|``|`webpack` relative or absolute path to the template. By default it will use `src/index.ejs` if it exists. Please see the [docs](https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md) for details|
|**`templateParameters`**|`{Boolean\|Object\|Function}`|``| Allows to overwrite the parameters used in the template |
|**`inject`**|`{Boolean\|String}`|`true`|`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`**|`{String}`|``|Adds the given favicon path to the output HTML|
|**`meta`**|`{Object}`|`{}`|Allows to inject `meta`-tags. E.g. `meta: {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`|
|**`base`**|`{Object\|String\|false}`|`false`|Inject a [`base`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base) tag. E.g. `base: "https://example.com/path/page.html`|
|**`minify`**|`{Boolean\|Object}`|`true` if `mode` is `'production'`, otherwise `false`|Controls if and in what ways the output should be minified. See [minification](#minification) below for more details.|
|**`hash`**|`{Boolean}`|`false`|If `true` then append a unique `webpack` compilation hash to all included scripts and CSS files. This is useful for cache busting|
|**`cache`**|`{Boolean}`|`true`|Emit the file only if it was changed|
|**`showErrors`**|`{Boolean}`|`true`|Errors details will be written into the HTML page|
|**`chunks`**|`{?}`|`?`|Allows you to add only some chunks (e.g only the unit-test chunk)|
|**[`chunksSortMode`](#plugins)**|`{String\|Function}`|`auto`|Allows to control how chunks should be sorted before they are included to the HTML. Allowed values are `'none' \| 'auto' \| 'dependency' \| 'manual' \| {Function}`|
|**[`excludeChunks`](#)**|`{Array.<string>}`|``|Allows you to skip some chunks (e.g don't add the unit-test chunk)|
|**[`xhtml`](#)**|`{Boolean}`|`false`|If `true` render the `link` tags as self-closing (XHTML compliant)|
|**`excludeChunks`**|`{Array.<string>}`|``|Allows you to skip some chunks (e.g don't add the unit-test chunk)|
|**`xhtml`**|`{Boolean}`|`false`|If `true` render the `link` tags as self-closing (XHTML compliant)|

Here's an example webpack config illustrating how to use these options

@@ -338,7 +340,7 @@ and the following options:
To use custom [html-minifier options](https://github.com/kangax/html-minifier#options-quick-reference)
pass an object to `minify` instead. This object will not be merged with the defaults above.

To disable minifcation during production mode set the `minify` option to `false`.
To disable minification during production mode set the `minify` option to `false`.

### Meta Tags

@@ -387,6 +389,39 @@ plugins: [
]
```

### Base Tag

When the `base` option is used,
html-webpack-plugin will inject a [base tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base).
By default, a base tag will not be injected.

The following two are identical and will both insert `<base href="http://example.com/some/page.html">`:

```js
new HtmlWebpackPlugin({
'base': 'http://example.com/some/page.html'
})
```

```js
new HtmlWebpackPlugin({
'base': { 'href': 'http://example.com/some/page.html' }
})
```

The `target` can be specified with the corresponding key:

```js
new HtmlWebpackPlugin({
'base': {
'href': 'http://example.com/some/page.html',
'target': '_blank'
}
})
```

which will inject the element `<base href="http://example.com/some/page.html" target="_blank">`.

### Long Term Caching

For long term caching add `contenthash/templatehash` to the filename.
@@ -508,7 +543,7 @@ class MyPlugin {
compiler.hooks.compilation.tap('MyPlugin', (compilation) => {
console.log('The compiler is starting a new compilation...')

// Staic Plugin interface |compilation |HOOK NAME | register listener
// Static Plugin interface |compilation |HOOK NAME | register listener
HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync(
'MyPlugin', // <-- Set a meaningful name here for stacktraces
(data, cb) => {
19 changes: 19 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Examples

A collection of repositories or pages using html-webpack-plugin.

Example | Link | Description
--- | --- | ---
Appcache | [appcache](./appcache)
Chunk Optimization | [chunk-optimization](./chunk-optimization)
Custom Template | [custom-template](./custom-template)
Default | [default](./default)
Favicon | [favicon](.\/favicon.)
Html Loader | [html-loader](./.html-loader)
Inline | [inline](./inline)
Javascript-advanced | [javascript-advanced](./javascript-advanced)
Javascript | [javascript](./javascript)
Pug Loader | [pug-loader](./pug-loader)
Sort Manually | [sort-manually](./sort-manually)
Template Parameters | [template-parameters](./template-parameters)
Landing Page | [webpack-static-webpage-example](https://github.com/TroyTae/webpack-static-webpage-example) | Landing page example that is optimized SEO and performance.
2 changes: 1 addition & 1 deletion examples/appcache/dist/webpack-4/manifest.appcache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CACHE MANIFEST
# c291a9f1884d47262395
# 2e387eef3192749536f8

0714810ae3fb211173e2964249507195.png
styles.css
2 changes: 1 addition & 1 deletion examples/chunk-optimization/dist/webpack-4/entryA.js
Original file line number Diff line number Diff line change
@@ -147,7 +147,7 @@
/******/
/******/
/******/ // add entry module to deferred list
/******/ deferredModules.push([2,0,5,1,2]);
/******/ deferredModules.push([2,1,5,2,0]);
/******/ // run deferred modules when ready
/******/ return checkDeferredModules();
/******/ })
8 changes: 2 additions & 6 deletions examples/chunk-optimization/dist/webpack-4/entryA~entryB.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[2],[
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[0],[
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

@@ -30,13 +30,9 @@ if(false) {}
/***/ (function(module, exports, __webpack_require__) {

exports = module.exports = __webpack_require__(4)(false);
// imports


// module
// Module
exports.push([module.i, "body {\n background: snow;\n}", ""]);

// exports


/***/ })
2 changes: 1 addition & 1 deletion examples/chunk-optimization/dist/webpack-4/entryB.js
Original file line number Diff line number Diff line change
@@ -147,7 +147,7 @@
/******/
/******/
/******/ // add entry module to deferred list
/******/ deferredModules.push([9,0,1,2]);
/******/ deferredModules.push([9,1,2,0]);
/******/ // run deferred modules when ready
/******/ return checkDeferredModules();
/******/ })
2 changes: 1 addition & 1 deletion examples/chunk-optimization/dist/webpack-4/libMath.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[0],{
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[1],{

/***/ 1:
/***/ (function(module, exports, __webpack_require__) {
147 changes: 79 additions & 68 deletions examples/chunk-optimization/dist/webpack-4/vendors~entryA~entryB.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,98 @@
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[1],[
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[2],[
/* 0 */,
/* 1 */,
/* 2 */,
/* 3 */,
/* 4 */
/***/ (function(module, exports) {
/***/ (function(module, exports, __webpack_require__) {

"use strict";


/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
// css base code, injected by the css-loader
module.exports = function(useSourceMap) {
var list = [];

// return the list of modules as css string
list.toString = function toString() {
return this.map(function (item) {
var content = cssWithMappingToString(item, useSourceMap);
if(item[2]) {
return "@media " + item[2] + "{" + content + "}";
} else {
return content;
}
}).join("");
};

// import a list of modules into the list
list.i = function(modules, mediaQuery) {
if(typeof modules === "string")
modules = [[null, modules, ""]];
var alreadyImportedModules = {};
for(var i = 0; i < this.length; i++) {
var id = this[i][0];
if(typeof id === "number")
alreadyImportedModules[id] = true;
}
for(i = 0; i < modules.length; i++) {
var item = modules[i];
// skip already imported module
// this implementation is not 100% perfect for weird media query combinations
// when a module is imported multiple times with different media queries.
// I hope this will never occur (Hey this way we have smaller bundles)
if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
if(mediaQuery && !item[2]) {
item[2] = mediaQuery;
} else if(mediaQuery) {
item[2] = "(" + item[2] + ") and (" + mediaQuery + ")";
}
list.push(item);
}
}
};
return list;
module.exports = function (useSourceMap) {
var list = []; // return the list of modules as css string

list.toString = function toString() {
return this.map(function (item) {
var content = cssWithMappingToString(item, useSourceMap);

if (item[2]) {
return '@media ' + item[2] + '{' + content + '}';
} else {
return content;
}
}).join('');
}; // import a list of modules into the list


list.i = function (modules, mediaQuery) {
if (typeof modules === 'string') {
modules = [[null, modules, '']];
}

var alreadyImportedModules = {};

for (var i = 0; i < this.length; i++) {
var id = this[i][0];

if (id != null) {
alreadyImportedModules[id] = true;
}
}

for (i = 0; i < modules.length; i++) {
var item = modules[i]; // skip already imported module
// this implementation is not 100% perfect for weird media query combinations
// when a module is imported multiple times with different media queries.
// I hope this will never occur (Hey this way we have smaller bundles)

if (item[0] == null || !alreadyImportedModules[item[0]]) {
if (mediaQuery && !item[2]) {
item[2] = mediaQuery;
} else if (mediaQuery) {
item[2] = '(' + item[2] + ') and (' + mediaQuery + ')';
}

list.push(item);
}
}
};

return list;
};

function cssWithMappingToString(item, useSourceMap) {
var content = item[1] || '';
var cssMapping = item[3];
if (!cssMapping) {
return content;
}
var content = item[1] || '';
var cssMapping = item[3];

if (useSourceMap && typeof btoa === 'function') {
var sourceMapping = toComment(cssMapping);
var sourceURLs = cssMapping.sources.map(function (source) {
return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */'
});
if (!cssMapping) {
return content;
}

return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
}
if (useSourceMap && typeof btoa === 'function') {
var sourceMapping = toComment(cssMapping);
var sourceURLs = cssMapping.sources.map(function (source) {
return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */';
});
return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
}

return [content].join('\n');
}
return [content].join('\n');
} // Adapted from convert-source-map (MIT)

// Adapted from convert-source-map (MIT)
function toComment(sourceMap) {
// eslint-disable-next-line no-undef
var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
var data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;

return '/*# ' + data + ' */';
function toComment(sourceMap) {
// eslint-disable-next-line no-undef
var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
var data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;
return '/*# ' + data + ' */';
}


/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
@@ -342,7 +351,9 @@ function addStyle (obj, options) {

// If a transform function was defined, run it on the css
if (options.transform && obj.css) {
result = options.transform(obj.css);
result = typeof options.transform === 'function'
? options.transform(obj.css)
: options.transform.default(obj.css);

if (result) {
// If transform returns a value, use that instead of the original css.
Loading