@nuxtjs/pwa Documentation

repository·main·Indexed 23 days ago

https://github.com/nuxt-community/pwa-module

A zero-config Progressive Web App (PWA) solution for Nuxt.js applications. Features include automatic service worker registration via Workbox, manifest generation, SEO and meta tag integration, and an icon module for generating various app icon sizes. Supports customization of the Web App Manifest, iOS status bar styles, Open Graph, and Twitter Card meta tags.

Tokens
6.7K
Snippets
17
Records
43
Agent score
79%

What's inside @nuxtjs/pwa

  1. Overview of @nuxtjs/pwa features

    main

    The @nuxtjs/pwa module provides a zero-config Progressive Web App (PWA) solution for Nuxt.js. Key capabilities include:

    • Service Worker Registration: Automatically registers a service worker to handle offline caching.
    • Manifest Generation: Automatically generates the manifest.json file required for PWA installation.
    • SEO Integration: Automatically adds SEO-friendly metadata that integrates with the web manifest.
    • Icon Generation: Automatically generates app icons in various required sizes.
    • Push Notifications: Supports free background push notifications via OneSignal integration.
  2. Use nativeUI for a native-app look

    main

    Setting meta.nativeUI to true optimizes the viewport and mobile settings to make the PWA feel more like a native mobile application.

    When nativeUI: true is set:

    • viewport defaults to: width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0, minimal-ui.
    • mobileAppIOS is enabled automatically (unless explicitly set to false).
  3. Understand the difference between `name` and `short_name`

    main

    When configuring your manifest, it is important to distinguish between these two identity fields:

    • name: The primary identifier of the app (maximum 45 characters). It is displayed in the install dialog, extension management UI, and the Chrome Web Store.
    • short_name: A shorter version of the app's name (maximum 12 characters recommended). It is used in UI areas with limited space, such as device home screens and the New Tab page. If short_name is not specified, the name will be used, but it may be truncated.
  4. Configure the Icon Module

    main

    The Icon Module automatically generates app icons and favicons of various sizes using jimp. It resizes a source icon using the cover method and populates the manifest.icons[] array with the resulting asset paths.

    You can customize the icon generation process by providing an icon object within the pwa configuration in your nuxt.config.js.

    pwa: {
      icon: {
        /* icon options */
      }
    }
  5. Install the @nuxtjs/pwa module

    main

    Install the @nuxtjs/pwa dependency as a development dependency using Yarn or NPM, then register it in your nuxt.config.js file under the buildModules array.

    Note: If you are using ssr: false in production mode without running nuxt generate, you must add the module to the modules array instead of buildModules.

    yarn add --dev @nuxtjs/pwa
    # or
    npm i --save-dev @nuxtjs/pwa
    // nuxt.config.js
    {
      buildModules: [
        '@nuxtjs/pwa',
      ]
    }
  6. Configure the Web App Manifest

    main

    You can configure the Web App Manifest by passing options to pwa.manifest within your nuxt.config.js. This allows you to override the default values derived from your package.json or the module's internal defaults.

    pwa: {
      manifest: {
        name: 'My Awesome App',
        lang: 'fa',
        useWebmanifestExtension: false
      }
    }