html-webpack-plugin 4.4.1 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +1 -0
- package/index.js +20 -9
- package/package.json +2 -2
- package/typings.d.ts +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
# [4.5.0](https://github.com/jantimon/html-webpack-plugin/compare/v4.4.1...v4.5.0) (2020-09-21)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* Add publicPath option to overrule the default path generation ([#1516](https://github.com/jantimon/html-webpack-plugin/issues/1516)) ([19b5122](https://github.com/jantimon/html-webpack-plugin/commit/19b5122))
|
|
11
|
+
* update webpack dependency range to allow installing webpack 5 beta ([f3ccdd5](https://github.com/jantimon/html-webpack-plugin/commit/f3ccdd5)), closes [#1504](https://github.com/jantimon/html-webpack-plugin/issues/1504)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
5
15
|
## [4.4.1](https://github.com/jantimon/html-webpack-plugin/compare/v4.4.0...v4.4.1) (2020-08-30)
|
|
6
16
|
|
|
7
17
|
|
package/README.md
CHANGED
|
@@ -138,6 +138,7 @@ Allowed values are as follows
|
|
|
138
138
|
|**`templateContent`**|`{string\|Function\|false}`|false| Can be used instead of `template` to provide an inline template - please read the [Writing Your Own Templates](https://github.com/jantimon/html-webpack-plugin#writing-your-own-templates) section |
|
|
139
139
|
|**`templateParameters`**|`{Boolean\|Object\|Function}`| `false`| Allows to overwrite the parameters used in the template - see [example](https://github.com/jantimon/html-webpack-plugin/tree/master/examples/template-parameters) |
|
|
140
140
|
|**`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 - see the [inject:false example](https://github.com/jantimon/html-webpack-plugin/tree/master/examples/custom-insertion-position)|
|
|
141
|
+
|**`publicPath`**|`{String|'auto'}`|`'auto'`|The publicPath used for script and link tags|
|
|
141
142
|
|**`scriptLoading`**|`{'blocking'\|'defer'}`|`'blocking'`| Modern browsers support non blocking javascript loading (`'defer'`) to improve the page startup performance. |
|
|
142
143
|
|**`favicon`**|`{String}`|``|Adds the given favicon path to the output HTML|
|
|
143
144
|
|**`meta`**|`{Object}`|`{}`|Allows to inject `meta`-tags. E.g. `meta: {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`|
|
package/index.js
CHANGED
|
@@ -44,6 +44,7 @@ class HtmlWebpackPlugin {
|
|
|
44
44
|
templateContent: false,
|
|
45
45
|
templateParameters: templateParametersGenerator,
|
|
46
46
|
filename: 'index.html',
|
|
47
|
+
publicPath: userOptions.publicPath === undefined ? 'auto' : userOptions.publicPath,
|
|
47
48
|
hash: false,
|
|
48
49
|
inject: userOptions.scriptLoading !== 'defer' ? 'body' : 'head',
|
|
49
50
|
scriptLoading: 'blocking',
|
|
@@ -167,7 +168,7 @@ class HtmlWebpackPlugin {
|
|
|
167
168
|
const isCompilationCached = templateResult.mainCompilationHash !== compilation.hash;
|
|
168
169
|
|
|
169
170
|
// Turn the entry point names into file paths
|
|
170
|
-
const assets = self.htmlWebpackPluginAssets(compilation, childCompilationOutputName, sortedEntryNames);
|
|
171
|
+
const assets = self.htmlWebpackPluginAssets(compilation, childCompilationOutputName, sortedEntryNames, this.options.publicPath);
|
|
171
172
|
|
|
172
173
|
// If the template and the assets did not change we don't have to emit the html
|
|
173
174
|
const assetJson = JSON.stringify(self.getAssetFiles(assets));
|
|
@@ -519,6 +520,7 @@ class HtmlWebpackPlugin {
|
|
|
519
520
|
* for all given entry names
|
|
520
521
|
* @param {WebpackCompilation} compilation
|
|
521
522
|
* @param {string[]} entryNames
|
|
523
|
+
* @param {string | 'auto'} customPublicPath
|
|
522
524
|
* @returns {{
|
|
523
525
|
publicPath: string,
|
|
524
526
|
js: Array<string>,
|
|
@@ -527,7 +529,7 @@ class HtmlWebpackPlugin {
|
|
|
527
529
|
favicon?: string
|
|
528
530
|
}}
|
|
529
531
|
*/
|
|
530
|
-
htmlWebpackPluginAssets (compilation, childCompilationOutputName, entryNames) {
|
|
532
|
+
htmlWebpackPluginAssets (compilation, childCompilationOutputName, entryNames, customPublicPath) {
|
|
531
533
|
const compilationHash = compilation.hash;
|
|
532
534
|
|
|
533
535
|
/**
|
|
@@ -539,13 +541,22 @@ class HtmlWebpackPlugin {
|
|
|
539
541
|
? compilation.mainTemplate.getPublicPath({ hash: compilationHash })
|
|
540
542
|
: compilation.getAssetPath(compilation.outputOptions.publicPath, { hash: compilationHash });
|
|
541
543
|
|
|
542
|
-
const isPublicPathDefined =
|
|
543
|
-
|
|
544
|
-
//
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
544
|
+
const isPublicPathDefined = webpackMajorVersion === 4
|
|
545
|
+
? webpackPublicPath.trim() !== ''
|
|
546
|
+
// Webpack 5 introduced "auto" - however it can not be retrieved at runtime
|
|
547
|
+
: webpackPublicPath.trim() !== '' && webpackPublicPath !== 'auto';
|
|
548
|
+
|
|
549
|
+
let publicPath =
|
|
550
|
+
// If the html-webpack-plugin options contain a custom public path uset it
|
|
551
|
+
customPublicPath !== 'auto'
|
|
552
|
+
? customPublicPath
|
|
553
|
+
: (isPublicPathDefined
|
|
554
|
+
// If a hard coded public path exists use it
|
|
555
|
+
? webpackPublicPath
|
|
556
|
+
// If no public path was set get a relative url path
|
|
557
|
+
: path.relative(path.resolve(compilation.options.output.path, path.dirname(childCompilationOutputName)), compilation.options.output.path)
|
|
558
|
+
.split(path.sep).join('/')
|
|
559
|
+
);
|
|
549
560
|
|
|
550
561
|
if (publicPath.length && publicPath.substr(-1, 1) !== '/') {
|
|
551
562
|
publicPath += '/';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-webpack-plugin",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Simplifies creation of HTML files to serve your webpack bundles",
|
|
6
6
|
"author": "Jan Nicklas <j.nicklas@me.com> (https://github.com/jantimon)",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"util.promisify": "1.0.0"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"webpack": "
|
|
64
|
+
"webpack": "^4.0.0 || ^5.0.0"
|
|
65
65
|
},
|
|
66
66
|
"keywords": [
|
|
67
67
|
"webpack",
|
package/typings.d.ts
CHANGED
|
@@ -63,6 +63,11 @@ declare namespace HtmlWebpackPlugin {
|
|
|
63
63
|
* @default 'index.html'
|
|
64
64
|
*/
|
|
65
65
|
filename: string;
|
|
66
|
+
/**
|
|
67
|
+
* By default the public path is set to `auto` - that way the html-webpack-plugin will try
|
|
68
|
+
* to set the publicPath according to the current filename and the webpack publicPath setting
|
|
69
|
+
*/
|
|
70
|
+
publicPath: string | 'auto';
|
|
66
71
|
/**
|
|
67
72
|
* If `true` then append a unique `webpack` compilation hash to all included scripts and CSS files.
|
|
68
73
|
* This is useful for cache busting
|