diff --git a/docs/migrations/migrate-from-v4.md b/docs/migrations/migrate-from-v4.md
index f41a5ea13f..d4181d0d3a 100644
--- a/docs/migrations/migrate-from-v4.md
+++ b/docs/migrations/migrate-from-v4.md
@@ -78,7 +78,7 @@ No longer supports generating project with `node-sass`. It has been [deprecated]
#### Underlying Loaders and Plugins
-* `html-webpack-plugin` is upgraded from v3 to v4, see more details in the [release announcement](https://dev.to/jantimon/html-webpack-plugin-4-has-been-released-125d).
+* `html-webpack-plugin` is upgraded from v3 to v5, and for webpack 4 users, v4 will be used. More details are available in the [release announcement of `html-webpack-plugin` v4](https://dev.to/jantimon/html-webpack-plugin-4-has-been-released-125d) and the [full changelog](https://github.com/jantimon/html-webpack-plugin/blob/master/CHANGELOG.md).
* `sass-loader` v7 support is dropped. See the v8 breaking changes at its [changelog](https://github.com/webpack-contrib/sass-loader/blob/master/CHANGELOG.md#800-2019-08-29).
* `postcss-loader` is upgraded from v3 to v4. Most notably, `PostCSS` options (`plugin` / `syntax` / `parser` / `stringifier`) are moved into the `postcssOptions` field. More details available at the [changelog](https://github.com/webpack-contrib/postcss-loader/blob/master/CHANGELOG.md#400-2020-09-07).
* `copy-webpack-plugin` is upgraded from v5 to v6. If you never customized its config through `config.plugin('copy')`, there should be no user-facing breaking changes. A full list of breaking changes is available at [`copy-webpack-plugin` v6.0.0 release](https://github.com/webpack-contrib/copy-webpack-plugin/releases/tag/v6.0.0).
diff --git a/packages/@vue/cli-plugin-babel/index.js b/packages/@vue/cli-plugin-babel/index.js
index 1b1df4824e..d42039c46d 100644
--- a/packages/@vue/cli-plugin-babel/index.js
+++ b/packages/@vue/cli-plugin-babel/index.js
@@ -39,6 +39,11 @@ module.exports = (api, options) => {
.test(/\.m?jsx?$/)
.exclude
.add(filepath => {
+ // With data URI support in webpack 5, filepath could be undefined
+ if (!filepath) {
+ return true
+ }
+
// always transpile js in vue files
if (/\.vue\.jsx?$/.test(filepath)) {
return false
diff --git a/packages/@vue/cli-plugin-pwa/package.json b/packages/@vue/cli-plugin-pwa/package.json
index d79b5b1e09..0e766e965e 100644
--- a/packages/@vue/cli-plugin-pwa/package.json
+++ b/packages/@vue/cli-plugin-pwa/package.json
@@ -24,7 +24,7 @@
},
"dependencies": {
"@vue/cli-shared-utils": "^5.0.0-alpha.3",
- "html-webpack-plugin": "^4.5.0",
+ "html-webpack-plugin": "^5.0.0",
"webpack": "^5.10.0",
"workbox-webpack-plugin": "^6.0.2"
},
diff --git a/packages/@vue/cli-plugin-webpack-4/generator.js b/packages/@vue/cli-plugin-webpack-4/generator.js
index 195d1476a9..1458a6b128 100644
--- a/packages/@vue/cli-plugin-webpack-4/generator.js
+++ b/packages/@vue/cli-plugin-webpack-4/generator.js
@@ -8,7 +8,10 @@ module.exports = (api) => {
// Yarn and PNPM 5.10+ support this feature
// So we'll try to use that whenever possible
resolutions: {
- '@vue/cli-*/webpack': '^4.0.0'
+ '@vue/cli-*/webpack': '^4.0.0',
+ 'html-webpack-plugin': '^4.5.1'
}
})
+
+ // TODO: if uses sass, replace sass-loader@11 with sass-loader@10
}
diff --git a/packages/@vue/cli-plugin-webpack-4/index.js b/packages/@vue/cli-plugin-webpack-4/index.js
index 5497b1d151..3f692ae078 100644
--- a/packages/@vue/cli-plugin-webpack-4/index.js
+++ b/packages/@vue/cli-plugin-webpack-4/index.js
@@ -1,8 +1,13 @@
+const path = require('path')
+const moduleAlias = require('module-alias')
+
+const htmlWebpackPlugin4Path = path.dirname(require.resolve('html-webpack-plugin/package.json'))
+// We have to use module-alias for html-webpack-plguin, as it is required by many other plugins
+// as peer dependency for its `getHooks` API.
+// Should add the alias as early as possible to avoid problems
+// TODO: add debugging log here
+moduleAlias.addAlias('html-webpack-plugin', htmlWebpackPlugin4Path)
+
/** @type {import('@vue/cli-service').ServicePlugin} */
-module.exports = () => {
- // TODO:
- // terser-webpack-plugin v4
- // copy-webpack-plugin v6
- // html-webpack-plugin v4
- // css-minimizer-webpack-plugin v1
+module.exports = (api, options) => {
}
diff --git a/packages/@vue/cli-plugin-webpack-4/package.json b/packages/@vue/cli-plugin-webpack-4/package.json
index 2cc6923809..e8640e6555 100644
--- a/packages/@vue/cli-plugin-webpack-4/package.json
+++ b/packages/@vue/cli-plugin-webpack-4/package.json
@@ -23,6 +23,8 @@
"access": "public"
},
"dependencies": {
+ "html-webpack-plugin": "^4.5.1",
+ "module-alias": "^2.2.2",
"webpack": "^4.44.2"
},
"peerDependencies": {
diff --git a/packages/@vue/cli-service/__tests__/build.spec.js b/packages/@vue/cli-service/__tests__/build.spec.js
index 92bbe79d91..8ebd58e65a 100644
--- a/packages/@vue/cli-service/__tests__/build.spec.js
+++ b/packages/@vue/cli-service/__tests__/build.spec.js
@@ -38,8 +38,8 @@ test('build', async () => {
// expect(index).toMatch(/]+app[^>]+\.css" rel="preload" as="style">/)
// should inject scripts
- expect(index).toMatch(/