UNPKG

22.4 kBMarkdownView Raw
1# ember-web-app
2[![Build Status](https://travis-ci.org/san650/ember-web-app.svg?branch=master)](https://travis-ci.org/san650/ember-web-app)
3[![Ember Observer Score](https://emberobserver.com/badges/ember-web-app.svg)](https://emberobserver.com/addons/ember-web-app)
4
5This Ember addon helps you configure and manage the web app manifest and related meta tags needed to create a Progressive Web Application
6
7From [MDN](https://developer.mozilla.org/en-US/docs/Web/Manifest)
8
9> The web app manifest provides information about an application (such as name,
10> author, icon, and description) in a text file. The purpose of the manifest is
11> to install web applications to the homescreen of a device, providing users
12> with quicker access and a richer experience.
13
14Addon features:
15
16* Generates a manifest.ember-web-app.json file using a JavaScript template
17* Uses fingerprint for images
18* Generates equivalent meta tags for supporting other devices (e.g. iPhone)
19* Validates the configuration
20
21See the [documentation](#documentation) section below for more information.
22
23## Table of content
24
25* [Installation](#installation)
26* [Example](#example)
27* [Configuration](#configuration)
28 * [Disable](#disable)
29 * [Fingerprint](#fingerprint)
30* [API documentation](#api-documentation)
31 * [`name`](#name)
32 * [`short_name`](#short_name)
33 * [`background_color`](#background_color)
34 * [`description`](#description)
35 * [`dir`](#dir)
36 * [`display`](#display)
37 * [`icons`](#icons)
38 * [`lang`](#lang)
39 * [`orientation`](#orientation)
40 * [`prefer_related_applications`](#prefer_related_applications)
41 * [`related_applications`](#related_applications)
42 * [`scope`](#scope)
43 * [`start_url`](#start_url)
44 * [`theme_color`](#theme_color)
45 * [`apple`](#apple)
46 * [`apple.statusBarStyle`](#applestatusbarstyle)
47 * [`apple.precomposed`](#appleprecomposed)
48 * [`apple.formatDetection`](#appleformatdetection)
49 * [`apple.webAppCapable`](#applewebappcapable)
50 * [`ms`](#ms)
51 * [`ms.tileColor`](#mstilecolor)
52* [Generating Icons](#generating-icons)
53* [Development](#development)
54* [Project's health](#projects-health)
55* [License](#license)
56
57## Installation
58
59```sh
60$ ember install ember-web-app
61```
62
63This generates a config/manifest.js configuration file.
64
65## Example
66
67Having the following configuration file `config/manifest.js`
68
69```js
70module.exports = function() {
71 return {
72 name: "Let's Cook",
73 short_name: "Let's Cook",
74 description: "An app for organizing your weekly menu and groceries list.",
75 start_url: "/",
76 display: "standalone",
77 background_color: "#ffa105",
78 theme_color: "#ffa105",
79
80 icons: [
81 {
82 src: "/images/icons/android-chrome-192x192.png",
83 sizes: "192x192",
84 type: "image/png"
85 },
86 {
87 src: "/images/icons/android-chrome-512x512.png",
88 sizes: "512x512",
89 type: "image/png"
90 },
91 {
92 src: "/images/icons/apple-touch-icon.png",
93 sizes: "180x180",
94 type: "image/png",
95 targets: ['apple']
96 },
97 {
98 src: "/images/icons/mstile-150x150.png",
99 element: "150x150",
100 targets: ['ms']
101 }
102 ],
103
104 apple: {
105 statusBarStyle: 'black-translucent'
106 },
107
108 ms: {
109 tileColor: '#ffffff'
110 }
111 }
112}
113```
114
115It will generate the following meta tags
116
117`index.html`
118
119```html
120<link rel="manifest" href="/manifest.webmanifest">
121
122<link rel="apple-touch-icon" href="/images/icons/android-chrome-192x192-883114367f2d72fc9a509409454a1e73.png" sizes="192x192">
123<link rel="apple-touch-icon" href="/images/icons/android-chrome-512x512-af3d768ff652dc2be589a3c22c6dc827.png" sizes="512x512">
124<link rel="apple-touch-icon" href="/images/icons/apple-touch-icon-36cba25bc155e8ba414265f9d85861ca.png" sizes="180x180">
125
126<meta name="theme-color" content="#ffa105">
127
128<meta name="apple-mobile-web-app-capable" content="yes">
129<meta name="apple-mobile-web-app-title" content="Let's Cook">
130<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
131
132<meta name="msapplication-config" content="/browserconfig.xml">
133```
134
135and the following `manifest.webmanifest` file
136
137```json
138{
139 "name": "Let's Cook",
140 "short_name": "Let's Cook",
141 "description": "An app for organizing your weekly menu and groceries list.",
142 "start_url": "/",
143 "display": "standalone",
144 "background_color": "#ffa105",
145 "theme_color": "#ffa105",
146 "icons": [
147 {
148 "src": "/images/icons/android-chrome-192x192-883114367f2d72fc9a509409454a1e73.png",
149 "sizes": "192x192",
150 "type":"image/png"
151 },
152 {
153 "src": "/images/icons/android-chrome-512x512-af3d768ff652dc2be589a3c22c6dc827.png",
154 "sizes": "512x512",
155 "type": "image/png"
156 }
157 ]
158}
159```
160
161and the following `browserconfig.xml` file
162
163```xml
164<?xml version="1.0"?>
165<browserconfig>
166 <msapplication>
167 <tile>
168 <square150x150logo src="/images/icons/mstile-150x150.png"/>
169 <TileColor>#ffffff</TileColor>
170 </tile>
171 </msapplication>
172</browserconfig>
173```
174
175## Configuration
176
177### Disable
178
179You can disable the addon by adding a configuration option to `ember-cli-build.js` build file.
180
181```js
182var EmberApp = require('ember-cli/lib/broccoli/ember-app');
183
184module.exports = function(defaults) {
185 var options = {
186 'ember-web-app': {
187 enabled: false
188 }
189 };
190
191 var app = new EmberApp(defaults, options);
192
193 return app.toTree();
194};
195```
196
197### Fingerprint
198
199You can add fingerprint checksum to your manifest.webmanifest file by configuring [broccoli-asset-rev](https://github.com/rickharrison/broccoli-asset-rev).
200
201The following example prepends with a custom domain and adds fingerprint checksum to the manifest.webmanifest file.
202
203`ember-cli-build.js`
204
205```js
206var EmberApp = require('ember-cli/lib/broccoli/ember-app');
207var broccoliAssetRevDefaults = require( 'broccoli-asset-rev/lib/default-options' );
208
209module.exports = function(defaults) {
210 var options = {
211 fingerprint: {
212 extensions: broccoliAssetRevDefaults.concat(['webmanifest']),
213 prepend: 'https://www.example.com/'
214 }
215 };
216
217 var app = new EmberApp(defaults, options);
218
219 return app.toTree();
220};
221```
222
223Note that the `replaceExtensions` configuration from `broccoli-asset-rev` is updated internally by `ember-web-app` so you don't have to configure yourself on your project.
224
225## API documentation
226
227This Ember addon generates a [Web Application Manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest) at build time using the `config/manifest.js` configuration file.
228
229It also generates some compatibility meta tags for supporting vendor specific web application features like Apple's [Web Content For Safari](https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/Introduction/Introduction.html) and Microsoft's [Browser configuration schema](https://msdn.microsoft.com/en-us/library/dn320426%28v=vs.85%29.aspx) that don't yet support the Web Application Manifest standard.
230
231Internally, this addon takes into account four different types of targets for generating the web app manifest taking care of including some backward compatibility meta tags in order to support as many devices and browsers as possible. These targets are:
232
233* manifest (default target)
234* apple (to target iOS devices)
235* ms (to target Win8/Win10 devices)
236* android (to target options specific for android devices)
237
238Not all targets are used for all properties (actually, most properties are not affected by the targets).
239
240### List of supported properties.
241
242* [`name`](#name)
243* [`short_name`](#short_name)
244* [`background_color`](#background_color)
245* [`description`](#description)
246* [`dir`](#dir)
247* [`display`](#display)
248* [`icons`](#icons)
249* [`lang`](#lang)
250* [`orientation`](#orientation)
251* [`prefer_related_applications`](#prefer_related_applications)
252* [`related_applications`](#related_applications)
253* [`scope`](#scope)
254* [`start_url`](#start_url)
255* [`theme_color`](#theme_color)
256* [`apple`](#apple)
257 * [`apple.statusBarStyle`](#applestatusbarstyle)
258 * [`apple.precomposed`](#appleprecomposed)
259 * [`apple.formatDetection`](#appleformatdetection)
260* [`ms`](#ms)
261 * [`ms.tileColor`](#mstilecolor)
262
263#### `name`
264
265> Provides a human-readable name for the application as it is intended to be displayed to the user, for example among a list of other applications or as a label for an icon.
266
267Example
268
269```js
270manifest.name = "dummy";
271```
272
273| Target | Generates |
274| --- | --- |
275| `manifest` | `{ "name": "dummy" }`
276| `apple` | `<meta name="apple-mobile-web-app-title" content="dummy">`
277| `ms` | `<meta name="application-name" content="dummy">`
278| `android` | does not apply
279
280#### `short_name`
281
282> Provides a short human-readable name for the application. This is intended for use where there is insufficient space to display the full name of the web application.
283
284Example
285
286```js
287manifest.short_name = "dummy";
288```
289
290| Target | Generates |
291| --- | --- |
292| `manifest` | `{ "short_name": "dummy" }`
293| `apple` | does not apply
294| `ms` | does not apply
295| `android` | does not apply
296
297#### `background_color`
298
299> Defines the expected background color for the web application.
300
301Example
302
303```js
304manifest.background_color = "#fff";
305```
306
307| Target | Generates |
308| --- | --- |
309| `manifest` | `{ "background_color": "#fff" }`
310| `apple` | does not apply
311| `ms` | does not apply
312| `android` | does not apply
313
314#### `description`
315
316> Provides a general description of what the web application does.
317
318Example
319
320```js
321manifest.description = "Lorem ipsum dolor";
322```
323
324| Target | Generates |
325| --- | --- |
326| `manifest` | `{ "description": "Lorem ipsum dolor" }`
327| `apple` | does not apply
328| `ms` | does not apply
329| `android` | does not apply
330
331#### `dir`
332
333> Specifies the primary text direction for the `name`, `short_name`, and description members.
334
335Possible values:
336 * ltr (left-to-right)
337 * rtl (right-to-left)
338 * auto
339
340Example
341
342```js
343manifest.dir = "ltr";
344```
345
346| Target | Generates |
347| --- | --- |
348| `manifest` | `{ "dir": "ltr" }`
349| `apple` | does not apply
350| `ms` | does not apply
351| `android` | does not apply
352
353#### `display`
354
355> Defines the developer's preferred display mode for the web application.
356
357Possible values:
358 * fullscreen
359 * standalone
360 * minimal-ui
361 * browser
362
363The default value for `display` is `browser` when is not defined.
364
365Example
366
367```js
368manifest.display = "fullscreen";
369```
370
371| Target | Generates |
372| --- | --- |
373| `manifest` | `{ "display": "fullscreen" }`
374| `apple` | `<meta name="apple-mobile-web-app-capable" content="yes">`
375| `ms` | does not apply
376| `android` | does not apply
377
378__Note that for iOS the meta tag will be render with value `yes` only when display is `fullscreen` or `standalone`.__
379
380#### `icons`
381
382> Specifies an array of image objects that can serve as application icons in various contexts. For example, they can be used to represent the web application amongst a list of other applications, or to integrate the web application with an OS's task switcher and/or system preferences.
383
384Image object members:
385 * `src` The path to the image file.
386 * `sizes` A string containing space-separated image dimensions.
387 * `type` A hint as to the media type of the image.
388 * `targets` **Non standard** Targets for the images. ['manifest', 'apple'] by default.
389 * `element` **Non standard** Only when the target is `ms`. Must be one of `square70x70logo`, `square150x150logo`, `wide310x150logo` or `square310x310logo`.
390 * `safariPinnedTabColor` **Non standard** Only when the target is `safari-pinned-tab`. Can specify a single color with a hexadecimal value (#990000), an RGB value (rgb(153, 0, 0)), or a recognized color-keyword, such as: red, lime, or navy..
391
392Example
393
394```js
395icons: [
396 {
397 src: '/foo/bar.png',
398 sizes: '180x180'
399 },
400 {
401 src: '/bar/baz.png',
402 sizes: '280x280',
403 targets: ['apple'] // non-standard property
404 },
405 {
406 src: '/bar/fav.png',
407 sizes: '32x32',
408 targets: ['favicon']
409 },
410 {
411 src: '/bar/ms.png',
412 element: 'square70x70logo', // non-standard property
413 targets: ['ms'] // non-standard-property
414 },
415 {
416 src: '/foo/monochrome.svg',
417 safariPinnedTabColor: '#cc6600', // non-standard property
418 targets: ['safari-pinned-tab'] // non-standard-property
419 }
420];
421```
422
423| Target | Generates |
424| --- | --- |
425| `manifest` | `{ "icons": [ { "src": "/foo/bar.png", "sizes": "180x180" } ] }`
426| `apple` | `<link rel="apple-touch-icon" href="/foo/bar.png" sizes="180x180">` `<link rel="apple-touch-icon" href="/foo/bar.png" sizes="280x280">`
427| `android` | does not apply
428| `favicon` | `<link rel="icon" href="/bar/fav.png" sizes="32x32">`
429| `ms` | icon in `browserconfig.xml`
430| `safari-pinned-tab` | `<link rel="mask-icon" href="/foo/monochrome.svg" color="#cc6600">`
431
432#### `lang`
433
434> Specifies the primary language for the values in the name and short_name members.
435
436Example
437
438```js
439manifest.lang = "es-UY";
440```
441
442| Target | Generates |
443| --- | --- |
444| `manifest` | `{ "lang": "es-UY" }`
445| `apple` | does not apply
446| `ms` | does not apply
447| `android` | does not apply
448
449#### `orientation`
450
451> Defines the default orientation for all the web application's top level browsing contexts.
452
453Possible values:
454 * any
455 * natural
456 * landscape
457 * landscape-primary
458 * landscape-secondary
459 * portrait
460 * portrait-primary
461 * portrait-secondary
462
463Example
464
465```js
466manifest.orientation = "portrait";
467```
468
469| Target | Generates |
470| --- | --- |
471| `manifest` | `{ "orientation": "portrait" }`
472| `apple` | does not apply
473| `ms` | does not apply
474| `android` | does not apply
475
476#### `prefer_related_applications`
477
478> Specifies a boolean value that hints for the user agent to indicate to the user that the specified related applications are available, and recommended over the web application.
479
480Possible values:
481 * true
482 * false
483
484Example
485
486```js
487manifest.prefer_related_applications = true;
488```
489
490| Target | Generates |
491| --- | --- |
492| `manifest` | `{ "prefer_related_applications": true }`
493| `apple` | does not apply
494| `ms` | does not apply
495| `android` | does not apply
496
497#### `related_applications`
498
499> Specifies an array of "application objects" representing native applications that are installable by, or accessible to, the underlying platform.
500
501Application object members:
502 * `platform` The platform on which the application can be found.
503 * `url` The URL at which the application can be found.
504 * `id` The ID used to represent the application on the specified platform.
505
506Example
507
508```js
509manifest.prefer_related_applications = true;
510manifest.related_applications = [
511 {
512 "platform": "itunes",
513 "url": "https://itunes.apple.com/app/example-app1/id123456789"
514 }
515];
516```
517
518| Target | Generates |
519| --- | --- |
520| `manifest` | `{ "prefer_related_applications": true, "related_applications": [{"platform": "itunes", "url": "https://itunes.apple.com/app/example-app1/id123456789" }] }`
521| `apple` | does not apply
522| `ms` | does not apply
523| `android` | does not apply
524
525#### `scope`
526
527> Defines the navigation scope of this web application's application context. This basically restricts what web pages can be viewed while the manifest is applied.
528
529Example
530
531```js
532manifest.scope = "/myapp/";
533```
534
535| Target | Generates |
536| --- | --- |
537| `manifest` | `{ "scope": "/myapp/" }`
538| `apple` | does not apply
539| `ms` | does not apply
540| `android` | does not apply
541
542#### `start_url`
543
544> Specifies the URL that loads when a user launches the application from a device.
545
546Example
547
548```js
549manifest.start_url = "./?utm_source=web_app_manifest";
550```
551
552| Target | Generates |
553| --- | --- |
554| `manifest` | `{ "start_url": "./?utm_source=web_app_manifest" }`
555| `apple` | does not apply
556| `ms` | does not apply
557| `android` | does not apply
558
559#### `theme_color`
560
561> Defines the default theme color for an application. This sometimes affects how the application is displayed by the OS.
562
563Example
564
565```js
566manifest.theme_color = "aliceblue";
567```
568
569| Target | Generates |
570| --- | --- |
571| `manifest` | `{ "theme_color": "aliceblue" }`
572| `apple` | does not apply
573| `ms` | does not apply
574| `android` | `<meta name="theme-color" content="aliceblue">`
575
576### Vendor specific properties (non-standard)
577
578#### `apple`
579
580> Turns on/off the generation of Apple-specific meta and link tags.
581
582Possible values:
583 * `true` Turn on. This is the default value.
584 * `false` Turn off.
585 * An object with custom settings (see the settings below)
586
587Example
588
589```js
590manifest.apple = false;
591```
592
593| Target | Generates |
594| --- | --- |
595| `manifest` | `{ "apple": false }`
596| `apple` | __returns an empty string__
597| `ms` | does not apply
598| `android` | does not apply
599
600#### `apple.webAppCapable`
601
602> Overrides `manifest.display` for the generation of the `apple-mobile-web-app-capable` meta tag.
603
604Possible values:
605 * `true` Turn on.
606 * `false` Turn off.
607
608Example
609
610```js
611manifest = {
612 display: 'standalone',
613 apple: {
614 webAppCapable: false
615 }
616};
617```
618
619| Target | Generates |
620| --- | --- |
621| `manifest` | does not apply
622| `apple` | `<meta name="apple-mobile-web-app-capable" content="yes">`
623| `ms` | does not apply
624| `android` | does not apply
625
626
627#### `apple.statusBarStyle`
628
629> Sets the style of the status bar for a web application in iOS
630
631See [Changing the Status Bar Appearance](https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html#//apple_ref/doc/uid/TP40002051-CH3-SW1)
632
633Possible values:
634 * `default` The status bar appears normal.
635 * `black` The status bar has a black background.
636 * `black-translucent` The status bar is black and translucent.
637
638Note that if set to default or black, the web content is displayed below the status bar. If set to black-translucent, the web content is displayed on the entire screen, partially obscured by the status bar.
639
640Example
641
642```js
643manifest.apple = {
644 statusBarStyle: 'black-translucent'
645};
646```
647
648| Target | Generates |
649| --- | --- |
650| `manifest` | does not apply
651| `apple` | `<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">`
652| `ms` | does not apply
653| `android` | does not apply
654
655#### `apple.precomposed`
656
657> Adds `precomposed` suffix to Apple touch icons
658
659See [Precomposed Keyword for Apple touch icons](https://mathiasbynens.be/notes/touch-icons#effects)
660
661Possible values:
662 * `true` Adds precomposed suffix.
663 * `false` (default) Does not add precomposed suffix.
664
665Example
666
667```js
668manifest.apple = {
669 precomposed: 'true'
670};
671```
672
673| Target | Generates |
674| --- | --- |
675| `manifest` | does not apply
676| `apple` | `<link rel="apple-touch-icon-precomposed" href="/images/icons/apple-touch-icon-192x192.png" sizes="192x192">`
677| `ms` | does not apply
678| `android` | does not apply
679
680#### `apple.formatDetection`
681
682> Adds `format-detection` meta tag if needed
683
684See [Safari HTML Reference](https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html#//apple_ref/doc/uid/TP40008193-SW5)
685
686Possible values:
687 * An object with following settings
688 * `telephone: false` Disables automatic phone number detection.
689
690Example
691
692```js
693manifest.apple = {
694 formatDetection: {
695 telephone: false
696 }
697};
698```
699
700| Target | Generates |
701| --- | --- |
702| `manifest` | does not apply
703| `apple` | `<meta name="format-detection" content="telephone=no">`
704| `ms` | does not apply
705| `android` | does not apply
706
707#### `ms`
708
709> Turns on/off the generation of Microsoft-specific meta and link tags.
710
711Possible values:
712 * `true` Turn on.
713 * `false` Turn off. This is the default value.
714 * An object with custom settings (see the settings below)
715
716Example
717
718```js
719manifest.ms = false;
720```
721
722#### `ms.tileColor`
723
724> Sets the `<TileColor>` property in `browserconfig.xml`.
725
726See [Browser configuration schema reference](https://msdn.microsoft.com/en-us/library/dn320426(v=vs.85).aspx)
727
728Possible values:
729 * A color in hex format.
730
731Example
732
733```js
734manifest.ms = {
735 tileColor: '#ffffff'
736};
737```
738
739## Generating Icons
740
741`ember-web-app` doesn't generate icons or images. If you want to automate the generation of icons starting from a master image, you can install `ember-cli-image-transformer`.
742
743Managing all the various icon sizes and types can be overwhelming. One solution is to start with a base image which can be use to generate the necessary icon permutations for your environment. You can use [ember-cli-image-transformer](https://github.com/jrjohnson/ember-cli-image-transformer) to handle this task.
744
745If your `manifest.js` looks like this and needs a 192px and a 512px icon:
746
747```javascript
748// config/manifest.js
749export default function() {
750 return {
751 icons: [
752 {
753 src: '/assets/icons/appicon-32.png',
754 sizes: `32x32`,
755 targets: ['favicon']
756 },
757 ...[192, 280, 512].map((size) => ({
758 src: `/assets/icons/appicon-${size}.png`,
759 sizes: `${size}x${size}`
760 }))
761 ]
762 };
763}
764```
765
766You can start with a base `brand-icon.svg` image and automatically build the 192x192 and 512x512 versions by installing `ember-cli-image-transformer` and adding the necessary configuration to your `ember-cli-build.js` file:
767
768```javascript
769// ember-cli-build.js
770module.exports = function(defaults) {
771 var app = new EmberApp(defaults, {
772 'ember-cli-image-transformer': {
773 images: [
774 {
775 inputFilename: 'lib/images/brand-icon.svg',
776 outputFileName: 'appicon-',
777 convertTo: 'png',
778 destination: 'assets/icons/',
779 sizes: [32, 192, 280, 512]
780 }
781 ]
782 }
783 });
784```
785
786## Development
787
788```sh
789$ git clone https://github.com/san650/ember-web-app.git
790$ cd $_
791$ yarn # (or npm install)
792```
793
794Running tests
795
796```sh
797$ npm test
798```
799
800## Project's health
801
802[![Build Status](https://travis-ci.org/san650/ember-web-app.svg?branch=master)](https://travis-ci.org/san650/ember-web-app)
803[![Ember Observer Score](https://emberobserver.com/badges/ember-web-app.svg)](https://emberobserver.com/addons/ember-web-app)
804
805## License
806
807ember-web-app is licensed under the MIT license.
808
809See [LICENSE](./LICENSE) for the full license text.