Skip to content

Commit 6d1716e

Browse files
committed
fix: pwa plugin compat with webpack 4
1 parent 4c5784d commit 6d1716e

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

packages/@vue/cli-plugin-pwa/__tests__/pwaPlugin.spec.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ test('pwa', async () => {
2828

2929
// Make sure the base preload/prefetch are not affected
3030
const index = await project.read('dist/index.html')
31+
3132
// should split and preload app.js & vendor.js
32-
expect(index).toMatch(/<link rel=preload [^>]+app[^>]+\.js>/)
33-
expect(index).toMatch(/<link rel=preload [^>]+vendor[^>]+\.js>/)
34-
// should not preload manifest because it's inlined
35-
expect(index).not.toMatch(/<link rel=preload [^>]+manifest[^>]+\.js>/)
36-
// should inline manifest and webpack runtime
37-
expect(index).toMatch('webpackJsonp')
33+
expect(index).toMatch(/<link [^>]+js\/app[^>]+\.js rel=preload>/)
34+
expect(index).toMatch(/<link [^>]+js\/vendors~app[^>]+\.js rel=preload>/)
35+
// should preload css
36+
expect(index).toMatch(/<link [^>]+app[^>]+\.css rel=preload>/)
3837

3938
// PWA specific directives
4039
expect(index).toMatch(`<link rel=manifest href=/manifest.json>`)
41-
expect(index).toMatch(`<!--[if IE]><link rel="shortcut icon" href="/favicon.ico"><![endif]-->`)
40+
// favicon is not minified because it's technically a comment
41+
expect(index).toMatch(`<!--[if IE]><link rel="icon" href="/favicon.ico"><![endif]-->`)
4242
expect(index).toMatch(`<meta name=apple-mobile-web-app-capable content=no>`)
4343

4444
// should import service worker script

packages/@vue/cli-plugin-pwa/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = (api, options) => {
1010
.use(require('./lib/HtmlPwaPlugin'), [Object.assign({
1111
name
1212
}, userOptions)])
13+
.after('html')
1314

1415
// generate /service-worker.js in production mode
1516
if (process.env.NODE_ENV === 'production') {

packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const ID = 'vue-cli:pwa-html-plugin'
2+
13
const defaults = {
24
name: 'PWA app',
35
themeColor: '#4DBA87', // The Vue color
@@ -12,14 +14,14 @@ module.exports = class HtmlPwaPlugin {
1214
}
1315

1416
apply (compiler) {
15-
compiler.plugin('compilation', compilation => {
16-
compilation.plugin('html-webpack-plugin-before-html-processing', (data, cb) => {
17+
compiler.hooks.compilation.tap(ID, compilation => {
18+
compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tapAsync(ID, (data, cb) => {
1719
// wrap favicon in the base template with IE only comment
18-
data.html = data.html.replace(/<link rel="shortcut icon"[^>]+>/, '<!--[if IE]>$&<![endif]-->')
20+
data.html = data.html.replace(/<link rel="icon"[^>]+>/, '<!--[if IE]>$&<![endif]-->')
1921
cb(null, data)
2022
})
2123

22-
compilation.plugin('html-webpack-plugin-alter-asset-tags', (data, cb) => {
24+
compilation.hooks.htmlWebpackPluginAlterAssetTags.tapAsync(ID, (data, cb) => {
2325
const { name, themeColor, msTileColor, appleMobileWebAppCapable, appleMobileWebAppStatusBarStyle } = this.options
2426
const { publicPath } = compiler.options.output
2527

0 commit comments

Comments
 (0)