Skip to content

Commit ed69eca

Browse files
authoredNov 6, 2020
Updates for html-webpack-plugin and webpack v5 (#2651)
* Fix for some plugin weirdness * v4/v5 fixes
1 parent bf8c949 commit ed69eca

File tree

7 files changed

+736
-881
lines changed

7 files changed

+736
-881
lines changed
 

‎package-lock.json

+698-840
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@
7777
"globby": "^11.0.1",
7878
"gulp": "^4.0.2",
7979
"gzip-size": "^5.1.1",
80-
"html-webpack-plugin": "^4.5.0",
80+
"html-webpack-plugin-v4": "npm:html-webpack-plugin@^4.5.0",
81+
"html-webpack-plugin-v5": "npm:html-webpack-plugin@^5.0.0-alpha.5",
8182
"husky": "^4.2.5",
8283
"jsdoc": "^3.6.5",
8384
"jsdoc-baseline": "^0.1.5",
@@ -102,7 +103,7 @@
102103
"typescript": "^3.9.7",
103104
"upath": "^1.2.0",
104105
"webpack-v4": "npm:webpack@^4.44.2",
105-
"webpack-v5": "npm:webpack@^5.0.0",
106+
"webpack-v5": "npm:webpack@^5.1.0",
106107
"worker-plugin": "^5.0.0"
107108
}
108109
}

‎packages/workbox-webpack-plugin/src/lib/get-manifest-entries-from-compilation.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,10 @@ function filterAssets(compilation, config) {
140140
return filteredAssets;
141141
}
142142

143-
module.exports = async (mainCompilation, config) => {
144-
const filteredAssets = new Set();
145-
// children will be set for, e.g., html-webpack-plugin.
146-
for (const compilation of [mainCompilation, ...mainCompilation.children]) {
147-
for (const asset of filterAssets(compilation, config)) {
148-
filteredAssets.add(asset);
149-
}
150-
}
143+
module.exports = async (compilation, config) => {
144+
const filteredAssets = filterAssets(compilation, config);
151145

152-
const {publicPath} = mainCompilation.options.output;
146+
const {publicPath} = compilation.options.output;
153147

154148
const fileDetails = Array.from(filteredAssets).map((asset) => {
155149
return {
@@ -166,10 +160,10 @@ module.exports = async (mainCompilation, config) => {
166160
manifestTransforms: config.manifestTransforms,
167161
maximumFileSizeToCacheInBytes: config.maximumFileSizeToCacheInBytes,
168162
modifyURLPrefix: config.modifyURLPrefix,
169-
transformParam: mainCompilation,
163+
transformParam: compilation,
170164
});
171165

172-
mainCompilation.warnings = mainCompilation.warnings.concat(warnings || []);
166+
compilation.warnings = compilation.warnings.concat(warnings || []);
173167

174168
// Ensure that the entries are properly sorted by URL.
175169
const sortedEntries = manifestEntries.sort(

‎test/workbox-webpack-plugin/node/v4/generate-sw.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
// correct webpack is for this test.
1212
// See https://jeffy.info/2020/10/01/testing-multiple-webpack-versions.html
1313
try {
14+
delete require.cache[require.resolve('html-webpack-plugin')];
1415
delete require.cache[require.resolve('webpack')];
1516
} catch (error) {
16-
// Ignore if require.resolve('webpack') fails.
17+
// Ignore if require.resolve() fails.
1718
}
1819
const upath = require('upath');
19-
require('module-alias').addAlias(
20-
'webpack', upath.resolve('node_modules', 'webpack-v4'));
20+
const moduleAlias = require('module-alias');
21+
moduleAlias.addAlias('html-webpack-plugin', upath.resolve('node_modules',
22+
'html-webpack-plugin-v4'));
23+
moduleAlias.addAlias('webpack', upath.resolve('node_modules', 'webpack-v4'));
2124

2225
const CopyWebpackPlugin = require('copy-webpack-plugin');
2326
const HtmlWebpackPlugin = require('html-webpack-plugin');
@@ -477,10 +480,6 @@ describe(`[workbox-webpack-plugin] GenerateSW with webpack v4`, function() {
477480
await validateServiceWorkerRuntime({swFile, expectedMethodCalls: {
478481
importScripts: [[/^\.\/workbox-[0-9a-f]{8}$/]],
479482
precacheAndRoute: [[[{
480-
revision: /^[0-9a-f]{32}$/,
481-
// See https://github.com/webpack/webpack/issues/11425#issuecomment-692809539
482-
url: '__child-HtmlWebpackPlugin_0',
483-
}, {
484483
revision: /^[0-9a-f]{32}$/,
485484
url: /^entry1-[0-9a-f]{20}\.js$/,
486485
}, {

‎test/workbox-webpack-plugin/node/v4/inject-manifest.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
// correct webpack is for this test.
1212
// See https://jeffy.info/2020/10/01/testing-multiple-webpack-versions.html
1313
try {
14+
delete require.cache[require.resolve('html-webpack-plugin')];
1415
delete require.cache[require.resolve('webpack')];
1516
} catch (error) {
16-
// Ignore if require.resolve('webpack') fails.
17+
// Ignore if require.resolve() fails.
1718
}
1819
const upath = require('upath');
19-
require('module-alias').addAlias(
20-
'webpack', upath.resolve('node_modules', 'webpack-v4'));
20+
const moduleAlias = require('module-alias');
21+
moduleAlias.addAlias('html-webpack-plugin', upath.resolve('node_modules',
22+
'html-webpack-plugin-v4'));
23+
moduleAlias.addAlias('webpack', upath.resolve('node_modules', 'webpack-v4'));
2124

2225
const chai = require('chai');
2326
const chaiMatchPattern = require('chai-match-pattern');
@@ -388,10 +391,6 @@ describe(`[workbox-webpack-plugin] InjectManifest with webpack v4`, function() {
388391
entryPoint: 'injectManifest',
389392
expectedMethodCalls: {
390393
precacheAndRoute: [[[{
391-
revision: /^[0-9a-f]{32}$/,
392-
// See https://github.com/webpack/webpack/issues/11425#issuecomment-692809539
393-
url: '__child-HtmlWebpackPlugin_0',
394-
}, {
395394
revision: /^[0-9a-f]{32}$/,
396395
url: /^entry1-[0-9a-f]{20}\.js$/,
397396
}, {

‎test/workbox-webpack-plugin/node/v5/generate-sw.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
// correct webpack is for this test.
1212
// See https://jeffy.info/2020/10/01/testing-multiple-webpack-versions.html
1313
try {
14+
delete require.cache[require.resolve('html-webpack-plugin')];
1415
delete require.cache[require.resolve('webpack')];
1516
} catch (error) {
16-
// Ignore if require.resolve('webpack') fails.
17+
// Ignore if require.resolve() fails.
1718
}
1819
const upath = require('upath');
19-
require('module-alias').addAlias(
20-
'webpack', upath.resolve('node_modules', 'webpack-v5'));
20+
const moduleAlias = require('module-alias');
21+
moduleAlias.addAlias('html-webpack-plugin', upath.resolve('node_modules',
22+
'html-webpack-plugin-v5'));
23+
moduleAlias.addAlias('webpack', upath.resolve('node_modules', 'webpack-v5'));
2124

2225
const CopyWebpackPlugin = require('copy-webpack-plugin');
2326
const HtmlWebpackPlugin = require('html-webpack-plugin');
@@ -478,15 +481,14 @@ describe(`[workbox-webpack-plugin] GenerateSW with webpack v5`, function() {
478481
await validateServiceWorkerRuntime({swFile, expectedMethodCalls: {
479482
importScripts: [[/^\.\/workbox-[0-9a-f]{8}$/]],
480483
precacheAndRoute: [[[{
481-
revision: /^[0-9a-f]{32}$/,
482-
// See https://github.com/webpack/webpack/issues/11425#issuecomment-692809539
483-
url: '__child-HtmlWebpackPlugin_0',
484-
}, {
485484
revision: /^[0-9a-f]{32}$/,
486485
url: /^entry1-[0-9a-f]{20}\.js$/,
487486
}, {
488487
revision: /^[0-9a-f]{32}$/,
489488
url: /^entry2-[0-9a-f]{20}\.js$/,
489+
}, {
490+
revision: /^[0-9a-f]{32}$/,
491+
url: 'index.html',
490492
}], {}]],
491493
}});
492494

‎test/workbox-webpack-plugin/node/v5/inject-manifest.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
// correct webpack is for this test.
1212
// See https://jeffy.info/2020/10/01/testing-multiple-webpack-versions.html
1313
try {
14+
delete require.cache[require.resolve('html-webpack-plugin')];
1415
delete require.cache[require.resolve('webpack')];
1516
} catch (error) {
16-
// Ignore if require.resolve('webpack') fails.
17+
// Ignore if require.resolve() fails.
1718
}
1819
const upath = require('upath');
19-
require('module-alias').addAlias(
20-
'webpack', upath.resolve('node_modules', 'webpack-v5'));
20+
const moduleAlias = require('module-alias');
21+
moduleAlias.addAlias('html-webpack-plugin', upath.resolve('node_modules',
22+
'html-webpack-plugin-v5'));
23+
moduleAlias.addAlias('webpack', upath.resolve('node_modules', 'webpack-v5'));
2124

2225
const chai = require('chai');
2326
const chaiMatchPattern = require('chai-match-pattern');
@@ -390,15 +393,14 @@ describe(`[workbox-webpack-plugin] InjectManifest with webpack v5`, function() {
390393
entryPoint: 'injectManifest',
391394
expectedMethodCalls: {
392395
precacheAndRoute: [[[{
393-
revision: /^[0-9a-f]{32}$/,
394-
// See https://github.com/webpack/webpack/issues/11425#issuecomment-692809539
395-
url: '__child-HtmlWebpackPlugin_0',
396-
}, {
397396
revision: /^[0-9a-f]{32}$/,
398397
url: /^entry1-[0-9a-f]{20}\.js$/,
399398
}, {
400399
revision: /^[0-9a-f]{32}$/,
401400
url: /^entry2-[0-9a-f]{20}\.js$/,
401+
}, {
402+
revision: /^[0-9a-f]{32}$/,
403+
url: 'index.html',
402404
}], {}]],
403405
},
404406
});

0 commit comments

Comments
 (0)
Please sign in to comment.