Skip to content

fix config pwa.iconPaths is being ignored #6203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions packages/@vue/cli-plugin-pwa/__tests__/pwaPlugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,33 @@ test('pwa', async () => {
const project = await create('pwa-build', defaultPreset)
expect(project.has('src/registerServiceWorker.js')).toBe(true)

await project.write(
'my-service-worker.js',
`var manifest = self.__WB_MANIFEST; console.log('some string value')`
)
await project.write(
'vue.config.js',
`module.exports = {
pwa: {
name: 'NAME',
themeColor: '#123456',
msTileColor: '#234567',
workboxPluginMode: 'InjectManifest',
workboxOptions: {
swSrc: './my-service-worker.js',
swDest: 'sw.js'
},
iconPaths: {
favicon32: 'path/to/favicon32.png',
favicon16: 'path/to/favicon16.png',
appleTouchIcon: 'path/to/apple-touch-icon.png',
maskIcon: 'path/to/safari-pinned-tab.svg',
msTileImage: 'path/to/mstile.png'
}
}
}`
)

const { stdout } = await project.run('vue-cli-service build')
expect(stdout).toMatch('Build complete.')

Expand All @@ -26,6 +53,11 @@ test('pwa', async () => {
expect(project.has('dist/manifest.json')).toBe(true)
expect(project.has('dist/img/icons/android-chrome-512x512.png')).toBe(true)

// PWA service worker files
expect(project.has('dist/sw.js')).toBe(true)
const sw = await project.read('dist/sw.js')
expect(sw).toMatch(`some string value`)

// Make sure the base preload/prefetch are not affected
const index = await project.read('dist/index.html')

Expand All @@ -40,6 +72,22 @@ test('pwa', async () => {
// favicon is not minified because it's technically a comment
expect(index).toMatch(`<!--[if IE]><link rel="icon" href="/favicon.ico"><![endif]-->`)
expect(index).toMatch(`<meta name="apple-mobile-web-app-capable" content="no">`)
// check custom meta tags
expect(index).toMatch(`<meta name="theme-color" content="#123456">`)
expect(index).toMatch(`<meta name="msapplication-TileColor" content="#234567">`)
expect(index).toMatch(`<meta name="msapplication-TileImage" content="/path/to/mstile.png">`)
expect(index).toMatch(`<link rel="apple-touch-icon" href="/path/to/apple-touch-icon.png">`)
expect(index).toMatch(`<link rel="icon" type="image/png" sizes="32x32" href="/path/to/favicon32.png">`)
expect(index).toMatch(`<link rel="icon" type="image/png" sizes="16x16" href="/path/to/favicon16.png">`)

// PWA generated manifest
expect(project.has('dist/manifest.json')).toBe(true)
const manifest = JSON.parse(await project.read('dist/manifest.json'))
expect(manifest).toMatchObject({
'name': 'NAME',
'short_name': 'NAME',
'theme_color': '#123456'
})

// should import service worker script
const main = await project.read('src/main.js')
Expand Down
3 changes: 1 addition & 2 deletions packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ const defaultIconPaths = {
module.exports = class HtmlPwaPlugin {
constructor (options = {}) {
const iconPaths = Object.assign({}, defaultIconPaths, options.iconPaths)
delete options.iconPaths
this.options = Object.assign({ iconPaths: iconPaths }, defaults, options)
this.options = Object.assign({}, defaults, options, { iconPaths: iconPaths })
}

apply (compiler) {
Expand Down