html-webpack-plugin 5.1.0 → 5.2.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 +7 -0
- package/index.js +13 -4
- package/lib/child-compiler.js +11 -1
- package/package.json +3 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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
|
+
## [5.2.0](https://github.com/jantimon/html-webpack-plugin/compare/v5.1.0...v5.2.0) (2021-02-19)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* improve ssr ([73d2a66](https://github.com/jantimon/html-webpack-plugin/commit/73d2a660b10b9ebf8a341f0ddb173bcaaf1e513c))
|
|
11
|
+
|
|
5
12
|
## [5.1.0](https://github.com/jantimon/html-webpack-plugin/compare/v5.0.0...v5.1.0) (2021-02-12)
|
|
6
13
|
|
|
7
14
|
|
package/index.js
CHANGED
|
@@ -123,12 +123,20 @@ class HtmlWebpackPlugin {
|
|
|
123
123
|
return Promise.reject(new Error('The child compilation didn\'t provide a result'));
|
|
124
124
|
}
|
|
125
125
|
// The LibraryTemplatePlugin stores the template result in a local variable.
|
|
126
|
-
//
|
|
127
|
-
if (source
|
|
126
|
+
// By adding it to the end the value gets extracted during evaluation
|
|
127
|
+
if (source.indexOf('HTML_WEBPACK_PLUGIN_RESULT') >= 0) {
|
|
128
128
|
source += ';\nHTML_WEBPACK_PLUGIN_RESULT';
|
|
129
129
|
}
|
|
130
130
|
const templateWithoutLoaders = templateFilename.replace(/^.+!/, '').replace(/\?.+$/, '');
|
|
131
|
-
const vmContext = vm.createContext({
|
|
131
|
+
const vmContext = vm.createContext({
|
|
132
|
+
...global,
|
|
133
|
+
HTML_WEBPACK_PLUGIN: true,
|
|
134
|
+
require: require,
|
|
135
|
+
htmlWebpackPluginPublicPath:
|
|
136
|
+
publicPath,
|
|
137
|
+
URL: require('url').URL,
|
|
138
|
+
__filename: templateWithoutLoaders
|
|
139
|
+
});
|
|
132
140
|
const vmScript = new vm.Script(source, { filename: templateWithoutLoaders });
|
|
133
141
|
// Evaluate code and cast to string
|
|
134
142
|
let newSource;
|
|
@@ -147,7 +155,8 @@ class HtmlWebpackPlugin {
|
|
|
147
155
|
}
|
|
148
156
|
|
|
149
157
|
/**
|
|
150
|
-
*
|
|
158
|
+
* connect the html-webpack-plugin to the webpack compiler lifecycle hooks
|
|
159
|
+
*
|
|
151
160
|
* @param {import('webpack').Compiler} compiler
|
|
152
161
|
* @param {ProcessedHtmlWebpackOptions} options
|
|
153
162
|
* @param {HtmlWebpackPlugin} plugin
|
package/lib/child-compiler.js
CHANGED
|
@@ -75,6 +75,7 @@ class HtmlWebpackChildCompiler {
|
|
|
75
75
|
const webpack = mainCompilation.compiler.webpack;
|
|
76
76
|
const Compilation = webpack.Compilation;
|
|
77
77
|
|
|
78
|
+
const NodeTemplatePlugin = webpack.node.NodeTemplatePlugin;
|
|
78
79
|
const NodeTargetPlugin = webpack.node.NodeTargetPlugin;
|
|
79
80
|
const LoaderTargetPlugin = webpack.LoaderTargetPlugin;
|
|
80
81
|
const EntryPlugin = webpack.EntryPlugin;
|
|
@@ -103,6 +104,7 @@ class HtmlWebpackChildCompiler {
|
|
|
103
104
|
const childCompiler = mainCompilation.createChildCompiler(compilerName, outputOptions, [
|
|
104
105
|
// Compile the template to nodejs javascript
|
|
105
106
|
new NodeTargetPlugin(),
|
|
107
|
+
new NodeTemplatePlugin(),
|
|
106
108
|
new LoaderTargetPlugin('node'),
|
|
107
109
|
new webpack.library.EnableLibraryPlugin('var')
|
|
108
110
|
]);
|
|
@@ -114,10 +116,18 @@ class HtmlWebpackChildCompiler {
|
|
|
114
116
|
|
|
115
117
|
// Add all templates
|
|
116
118
|
this.templates.forEach((template, index) => {
|
|
117
|
-
new EntryPlugin(childCompiler.context, 'data:text/javascript,__webpack_public_path__ = htmlWebpackPluginPublicPath;', `HtmlWebpackPlugin_${index}-${this.id}`).apply(childCompiler);
|
|
119
|
+
new EntryPlugin(childCompiler.context, 'data:text/javascript,__webpack_public_path__ = __webpack_base_uri__ = htmlWebpackPluginPublicPath;', `HtmlWebpackPlugin_${index}-${this.id}`).apply(childCompiler);
|
|
118
120
|
new EntryPlugin(childCompiler.context, template, `HtmlWebpackPlugin_${index}-${this.id}`).apply(childCompiler);
|
|
119
121
|
});
|
|
120
122
|
|
|
123
|
+
// The templates are compiled and executed by NodeJS - similar to server side rendering
|
|
124
|
+
// Unfortunately this causes issues as some loaders require an absolute URL to support ES Modules
|
|
125
|
+
// The following config enables relative URL support for the child compiler
|
|
126
|
+
childCompiler.options.module = { ...childCompiler.options.module };
|
|
127
|
+
childCompiler.options.module.parser = { ...childCompiler.options.module.parser };
|
|
128
|
+
childCompiler.options.module.parser.javascript = { ...childCompiler.options.module.parser.javascript,
|
|
129
|
+
url: 'relative' };
|
|
130
|
+
|
|
121
131
|
this.compilationStartedTimestamp = new Date().getTime();
|
|
122
132
|
this.compilationPromise = new Promise((resolve, reject) => {
|
|
123
133
|
const extractedAssets = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-webpack-plugin",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.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)",
|
|
@@ -34,8 +34,7 @@
|
|
|
34
34
|
"css-loader": "5.0.1",
|
|
35
35
|
"cz-conventional-changelog": "2.1.0",
|
|
36
36
|
"dir-compare": "1.7.2",
|
|
37
|
-
"
|
|
38
|
-
"html-loader": "1.3.2",
|
|
37
|
+
"html-loader": "2.0.0",
|
|
39
38
|
"jest": "26.5.3",
|
|
40
39
|
"mini-css-extract-plugin": "1.0.0",
|
|
41
40
|
"pug": "2.0.3",
|
|
@@ -46,7 +45,7 @@
|
|
|
46
45
|
"standard-version": "9.1.0",
|
|
47
46
|
"style-loader": "2.0.0",
|
|
48
47
|
"typescript": "4.1.3",
|
|
49
|
-
"webpack": "
|
|
48
|
+
"webpack": "5.23.0",
|
|
50
49
|
"webpack-recompilation-simulator": "3.2.0",
|
|
51
50
|
"webpack-cli": "4.2.0"
|
|
52
51
|
},
|