Skip to content

Commit 4484e6c

Browse files
gangsthubpaul_meleropooya parsa
authored
feat(manifest): add useWebmanifestExtension option and improve docs (#241)
Co-authored-by: paul_melero <paulmelero@gmail> Co-authored-by: pooya parsa <pooya@pi0.ir>
1 parent 9248174 commit 4484e6c

4 files changed

Lines changed: 78 additions & 5 deletions

File tree

docs/modules/manifest.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,75 @@ sidebar: auto
99

1010
Manifest adds [Web App Manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest) with no pain.
1111

12-
You can pass options to `pwa.manifest` in `nuxt.config.js` to override defaults.
12+
You can pass options to `pwa.manifest` in `nuxt.config.js` to override defaults. Check the
13+
[valid options](https://developer.mozilla.org/en-US/docs/Web/Manifest#Members) available and and it's
14+
[default options](#default-options) for deeper insights.
1315

1416
```js
1517
pwa: {
1618
manifest: {
1719
name: 'My Awesome App',
18-
lang: 'fa'
20+
lang: 'fa',
21+
useWebmanifestExtension: false
1922
}
2023
}
2124
```
25+
26+
# Default options
27+
28+
| Property | Type | Default | Description |
29+
| --------------------------------- | --------------- | ------------------------------------------------------------ | --------------------------------------------------------------- |
30+
| `name` <sup>\*1</sup> | `String` | `package.json`'s name property | [maximum of 45 characters] |
31+
| `short_name` <sup>\*1</sup> | `String` | `package.json`'s name property | [maximum of 12 characters] |
32+
| `description` <sup>\*2</sup> | `String` | `package.json`'s description property | |
33+
| `icons` <sup>\*1</sup> | `Array<Object>` | `[]` | (See the [icon module]) |
34+
| `start_url` <sup>\*1</sup> | `String` | `routerBase + '?standalone=true'` | It has to be relative to where the manifest is placed |
35+
| `display` <sup>\*1</sup> | `String` | `'standalone'` | |
36+
| `background_color` <sup>\*2</sup> | `String` | `'#ffffff'` | |
37+
| `theme_color` <sup>\*2</sup> | `String` | `this.options.loading.color` | Nuxt [loading color] option |
38+
| `dir` | `String` | `'ltr'` | `ltr` or `rtl`. Used with `lang` |
39+
| `lang` | `String` | `'en'` | Recommended if used `dir` |
40+
| `useWebmanifestExtension` <sup>\*3</sup> | `Boolean` | `false` | Whether to use `webmanifest` file extension (or default `json`) |
41+
| `publicPath` | `String` | A combination of `routerBase` and `options.build.publicPath` | |
42+
43+
- <sup>\*1</sup> Mandatory (according [to Google](https://web.dev/add-manifest)).
44+
Although [official documentation](https://w3c.github.io/manifest/#json-schema) only mentions `name` and `icons`
45+
- <sup>\*2</sup> Recommended (according [to Google](https://web.dev/add-manifest))
46+
- <sup>\*3</sup> Please see [wiki](https://github.com/nuxt-community/pwa-module/wiki/.webmanifest)
47+
48+
[icon module]: https://pwa.nuxtjs.org/modules/icon.html
49+
[maximum of 45 characters]: https://developer.chrome.com/apps/manifest/name
50+
[maximum of 12 characters]: https://developer.chrome.com/apps/manifest/name
51+
[loading color]: https://nuxtjs.org/api/configuration-loading/#customizing-the-progress-bar
52+
53+
For more information, check out:
54+
55+
- the spec: https://w3c.github.io/manifest/
56+
- Pete LePage's article: https://web.dev/add-manifest/
57+
- MDN Docs: https://developer.mozilla.org/en-US/docs/Web/Manifest
58+
59+
## Difference between `name` and `short_name`:
60+
61+
### `name`
62+
63+
> The name (maximum of 45 characters) is the primary identifier of the app and is a required field. It is displayed in the following locations:
64+
>
65+
> - Install dialog
66+
> - Extension management UI
67+
> - Chrome Web Store
68+
69+
Source: https://developer.chrome.com/apps/manifest/name
70+
71+
### `short_name`
72+
73+
> The short_name (maximum of 12 characters recommended) is a short version of the app's name. It is an optional field and if not specified, the name will be used, > though it will likely be truncated. The short name is typically used where there is insufficient space to display the full name, such as:
74+
>
75+
> - Device home screens
76+
> - New Tab page
77+
78+
Source: https://developer.chrome.com/apps/manifest/name
79+
80+
## `useWebmanifestExtension`:
81+
82+
This options sets the manifest file extension to `.json` or `.webmanifest`. For more information, check
83+
[this wiki page](https://github.com/nuxt-community/pwa-module/wiki/.webmanifest).

lib/manifest/module.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ function addManifest (pwa) {
2828
display: 'standalone',
2929
background_color: '#ffffff',
3030
theme_color: this.options.loading && this.options.loading.color,
31-
lang: 'en'
31+
lang: 'en',
32+
useWebmanifestExtension: false
3233
}
3334

3435
const options = { ...defaults, ...pwa.manifest }
@@ -37,10 +38,17 @@ function addManifest (pwa) {
3738
const manifest = { ...options }
3839
delete manifest.src
3940
delete manifest.publicPath
41+
delete manifest.useWebmanifestExtension
4042

4143
// Stringify manifest & generate hash
4244
const manifestSource = JSON.stringify(manifest)
43-
const manifestFileName = `manifest.${hash(manifestSource).substr(0, 8)}.json`
45+
const manifestFileName = `manifest.${
46+
hash(manifestSource).substr(0, 8)
47+
}.${
48+
options.useWebmanifestExtension
49+
? 'webmanifest'
50+
: 'json'
51+
}`
4452

4553
// Merge final manifest into options.manifest for other modules
4654
if (!this.options.manifest) {

test/__snapshots__/pwa.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Array [
1717
"fixture/.nuxt/dist/client/icons/icon_384.b8f3a1.png",
1818
"fixture/.nuxt/dist/client/icons/icon_512.b8f3a1.png",
1919
"fixture/.nuxt/dist/client/icons/icon_64.b8f3a1.png",
20+
"fixture/.nuxt/dist/client/manifest.bee706d5.webmanifest",
2021
"fixture/.nuxt/dist/server",
2122
"fixture/.nuxt/dist/server/index.spa.html",
2223
"fixture/.nuxt/dist/server/index.ssr.html",
@@ -43,6 +44,7 @@ Array [
4344
"fixture/dist/_nuxt/icons/icon_384.b8f3a1.png",
4445
"fixture/dist/_nuxt/icons/icon_512.b8f3a1.png",
4546
"fixture/dist/_nuxt/icons/icon_64.b8f3a1.png",
47+
"fixture/dist/_nuxt/manifest.bee706d5.webmanifest",
4648
"fixture/dist/icon.png",
4749
"fixture/dist/index.html",
4850
"fixture/dist/offline.html",

test/fixture/nuxt.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module.exports = {
1212

1313
manifest: {
1414
name: 'Test Project Name',
15-
description: 'Test Project Description'
15+
description: 'Test Project Description',
16+
useWebmanifestExtension: true
1617
},
1718

1819
workbox: {

0 commit comments

Comments
 (0)