html-webpack-plugin
Advanced tools
Comparing version 4.3.0 to 4.4.0
@@ -5,2 +5,16 @@ # Change Log | ||
# [4.4.0](https://github.com/jantimon/html-webpack-plugin/compare/v4.3.0...v4.4.0) (2020-08-30) | ||
### Bug Fixes | ||
* fix typos in comments ([#1484](https://github.com/jantimon/html-webpack-plugin/issues/1484)) ([6b0711e](https://github.com/jantimon/html-webpack-plugin/commit/6b0711e)) | ||
### Features | ||
* added v5 compilation support and deleted depreciation warnings ([4ae7be8](https://github.com/jantimon/html-webpack-plugin/commit/4ae7be8)), closes [#1454](https://github.com/jantimon/html-webpack-plugin/issues/1454) | ||
# [4.3.0](https://github.com/jantimon/html-webpack-plugin/compare/v4.2.2...v4.3.0) (2020-04-30) | ||
@@ -7,0 +21,0 @@ |
27
index.js
@@ -30,2 +30,4 @@ // @ts-check | ||
const webpackMajorVersion = Number(require('webpack/package.json').version.split('.')[0]); | ||
class HtmlWebpackPlugin { | ||
@@ -153,3 +155,3 @@ /** | ||
const childCompilationOutputName = compilation.mainTemplate.getAssetPath(this.options.filename, 'compiledEntry' in templateResult ? { | ||
const compiledEntries = 'compiledEntry' in templateResult ? { | ||
hash: templateResult.compiledEntry.hash, | ||
@@ -159,4 +161,8 @@ chunk: templateResult.compiledEntry.entry | ||
hash: templateResult.mainCompilationHash | ||
}); | ||
}; | ||
const childCompilationOutputName = webpackMajorVersion === 4 | ||
? compilation.mainTemplate.getAssetPath(this.options.filename, compiledEntries) | ||
: compilation.getAssetPath(this.options.filename, compiledEntries); | ||
// If the child compilation was not executed during a previous main compile run | ||
@@ -207,3 +213,3 @@ // it is a cached result | ||
.then(({ assetTags }) => { | ||
// Inject scripts to body unless it set explictly to head | ||
// Inject scripts to body unless it set explicitly to head | ||
const scriptTarget = self.options.inject === 'head' ? 'head' : 'body'; | ||
@@ -221,3 +227,3 @@ // Group assets to `head` and `body` tag arrays | ||
// Turn the compiled tempalte into a nodejs function or into a nodejs string | ||
// Turn the compiled template into a nodejs function or into a nodejs string | ||
const templateEvaluationPromise = Promise.resolve() | ||
@@ -535,5 +541,8 @@ .then(() => { | ||
* if a path publicPath is set in the current webpack config use it otherwise | ||
* fallback to a realtive path | ||
* fallback to a relative path | ||
*/ | ||
const webpackPublicPath = compilation.mainTemplate.getPublicPath({ hash: compilationHash }); | ||
const webpackPublicPath = webpackMajorVersion === 4 | ||
? compilation.mainTemplate.getPublicPath({ hash: compilationHash }) | ||
: compilation.getAssetPath(compilation.outputOptions.publicPath, { hash: compilationHash }); | ||
const isPublicPathDefined = webpackPublicPath.trim() !== ''; | ||
@@ -594,3 +603,3 @@ let publicPath = isPublicPathDefined | ||
} | ||
// Prevent hot-module files from beeing included: | ||
// Prevent hot-module files from being included: | ||
const assetMetaInformation = asset.info || {}; | ||
@@ -632,4 +641,4 @@ return !(assetMetaInformation.hotModuleReplacement || assetMetaInformation.development); | ||
/** | ||
* Converts a favicon file from disk to a webpack ressource | ||
* and returns the url to the ressource | ||
* Converts a favicon file from disk to a webpack resource | ||
* and returns the url to the resource | ||
* | ||
@@ -636,0 +645,0 @@ * @param {string|false} faviconFilePath |
@@ -61,3 +61,3 @@ // @ts-check | ||
this.compiler = compiler; | ||
// Create a singlton instance for the compiler | ||
// Create a singleton instance for the compiler | ||
// if there is none | ||
@@ -64,0 +64,0 @@ if (compilerMap.has(compiler)) { |
@@ -21,4 +21,4 @@ // @ts-check | ||
/** | ||
* The HtmlWebpackChildCompiler is a helper to allow resusing one childCompiler | ||
* for multile HtmlWebpackPlugin instances to improve the compilation performance. | ||
* The HtmlWebpackChildCompiler is a helper to allow reusing one childCompiler | ||
* for multiple HtmlWebpackPlugin instances to improve the compilation performance. | ||
*/ | ||
@@ -57,3 +57,3 @@ class HtmlWebpackChildCompiler { | ||
* Returns true if the childCompiler is currently compiling | ||
* @retuns {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -65,3 +65,3 @@ isCompiling () { | ||
/** | ||
* Returns true if the childCOmpiler is done compiling | ||
* Returns true if the childCompiler is done compiling | ||
*/ | ||
@@ -124,3 +124,12 @@ didCompile () { | ||
if (childCompilation && childCompilation.errors && childCompilation.errors.length) { | ||
const errorDetails = childCompilation.errors.map(error => error.message + (error.error ? ':\n' + error.error : '')).join('\n'); | ||
const errorDetails = childCompilation.errors.map(error => { | ||
let message = error.message; | ||
if (error.error) { | ||
message += ':\n' + error.error; | ||
} | ||
if (error.stack) { | ||
message += '\n' + error.stack; | ||
} | ||
return message; | ||
}).join('\n'); | ||
reject(new Error('Child compilation failed:\n' + errorDetails)); | ||
@@ -166,8 +175,14 @@ return; | ||
function extractHelperFilesFromCompilation (mainCompilation, childCompilation, filename, childEntryChunks) { | ||
const webpackMajorVersion = Number(require('webpack/package.json').version.split('.')[0]); | ||
const helperAssetNames = childEntryChunks.map((entryChunk, index) => { | ||
return mainCompilation.mainTemplate.getAssetPath(filename, { | ||
const entryConfig = { | ||
hash: childCompilation.hash, | ||
chunk: entryChunk, | ||
name: `HtmlWebpackPlugin_${index}` | ||
}); | ||
}; | ||
return webpackMajorVersion === 4 | ||
? mainCompilation.mainTemplate.getAssetPath(filename, entryConfig) | ||
: mainCompilation.getAssetPath(filename, entryConfig); | ||
}); | ||
@@ -174,0 +189,0 @@ |
// @ts-check | ||
/** | ||
* To use the availble webpack core api | ||
* To use the available webpack core api | ||
* we have to use different child compilers | ||
@@ -5,0 +5,0 @@ * depending on the used webpack version |
@@ -5,4 +5,4 @@ // @ts-check | ||
* @file | ||
* This file provides to helper to create html as a object repesentation as | ||
* thoses objects are easier to modify than pure string representations | ||
* This file provides to helper to create html as a object representation as | ||
* those objects are easier to modify than pure string representations | ||
* | ||
@@ -51,3 +51,3 @@ * Usage: | ||
* @param {string} tagName | ||
* the name of the tage e.g. 'div' | ||
* the name of the tag e.g. 'div' | ||
* | ||
@@ -54,0 +54,0 @@ * @param {{[attributeName: string]: string|boolean}} [attributes] |
{ | ||
"name": "html-webpack-plugin", | ||
"version": "4.3.0", | ||
"version": "4.4.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Simplifies creation of HTML files to serve your webpack bundles", |
@@ -81,2 +81,3 @@ [![npm][npm]][npm-url] | ||
* [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. | ||
* [html-webpack-skip-assets-plugin](https://github.com/swimmadude66/html-webpack-skip-assets-plugin) Skip adding certain output files to the html file. Built as a drop-in replacement for [html-webpack-exclude-assets-plugin](https://www.npmjs.com/package/html-webpack-exclude-assets-plugin) and works with newer [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin) versions | ||
@@ -150,3 +151,3 @@ | ||
|**`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' \| 'manual' \| {Function}`| | ||
|**`chunksSortMode`**|`{String\|Function}`|`auto`|Allows to control how chunks should be sorted before they are included to the HTML. Allowed values are `'none' \| 'auto' \| 'manual' \| {Function}`| | ||
|**`excludeChunks`**|`{Array.<string>}`|``|Allows you to skip some chunks (e.g don't add the unit-test chunk)| | ||
@@ -153,0 +154,0 @@ |**`xhtml`**|`{Boolean}`|`false`|If `true` render the `link` tags as self-closing (XHTML compliant)| |
@@ -13,2 +13,13 @@ import { AsyncSeriesWaterfallHook } from "tapable"; | ||
static getHooks(compilation: compilation.Compilation): HtmlWebpackPlugin.Hooks; | ||
/** | ||
* Static helper to create a tag object to be get injected into the dom | ||
*/ | ||
static createHtmlTagObject( | ||
tagName: string, | ||
attributes?: { [attributeName: string]: string | boolean }, | ||
innerHTML?: string | ||
): HtmlTagObject; | ||
static readonly version: number; | ||
} | ||
@@ -27,3 +38,3 @@ | ||
* Emit the file only if it was changed. | ||
* Default: `true`. | ||
* @default true | ||
*/ | ||
@@ -37,3 +48,3 @@ cache: boolean; | ||
* Allows to control how chunks should be sorted before they are included to the html. | ||
* Default: `'auto'`. | ||
* @default 'auto' | ||
*/ | ||
@@ -45,3 +56,3 @@ chunksSortMode: | ||
/** | ||
* List all entries which should not be injeccted | ||
* List all entries which should not be injected | ||
*/ | ||
@@ -55,4 +66,4 @@ excludeChunks: string[]; | ||
* The file to write the HTML to. | ||
* Defaults to `index.html`. | ||
* Supports subdirectories eg: `assets/admin.html` | ||
* @default 'index.html' | ||
*/ | ||
@@ -78,3 +89,3 @@ filename: string; | ||
* | ||
* The default behaviour is blocking | ||
* @default 'blocking' | ||
*/ | ||
@@ -96,7 +107,7 @@ scriptLoading: | ||
/** | ||
* HTML Minification options accepts the following valeus: | ||
* HTML Minification options accepts the following values: | ||
* - Set to `false` to disable minifcation | ||
* - Set to `'auto'` to enable minifcation only for production mode | ||
* - Set to custom minification according to | ||
* @https://github.com/kangax/html-minifier#options-quick-reference | ||
* {@link https://github.com/kangax/html-minifier#options-quick-reference} | ||
*/ | ||
@@ -103,0 +114,0 @@ minify: 'auto' | boolean | MinifyOptions; |
142221
2208
660