### PWA Module Integration Example Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/index.md Demonstrates how to integrate the Nuxt PWA Module into a Nuxt.js project. It shows the basic setup and usage within a Nuxt configuration file. ```javascript export default { modules: [ '@nuxtjs/pwa', ], pwa: { manifest: { name: 'My Nuxt PWA', short_name: 'NuxtPWA', description: 'My awesome Nuxt.js PWA', lang: 'en', theme_color: '#ffffff', background_color: '#ffffff', display: 'standalone', scope: '/', start_url: '/', icons: [ { src: '/icons/icon_64.png', sizes: '64x64', type: 'image/png' }, { src: '/icons/icon_120.png', sizes: '120x120', type: 'image/png' }, { src: '/icons/icon_192.192.png', sizes: '192x192', type: 'image/png' }, { src: '/icons/icon_512.512.png', sizes: '512x512', type: 'image/png' } ] } } } ``` -------------------------------- ### Install Nuxt PWA Module Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/setup.md Installs the Nuxt PWA module as a development dependency using either Yarn or NPM. ```bash yarn add --dev @nuxtjs/pwa ``` ```bash npm i --save-dev @nuxtjs/pwa ``` -------------------------------- ### Preview Static Site Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/README.md Starts a server to preview the statically generated Nuxt PWA Module application. ```bash yarn start ``` -------------------------------- ### Run Development Server Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/README.md Starts the development server for the Nuxt PWA Module. ```bash yarn dev ``` -------------------------------- ### Install Dependencies Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/README.md Installs the necessary dependencies for the project using Yarn. ```bash yarn install ``` -------------------------------- ### Nuxt PWA Meta Configuration Example Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/meta.md Demonstrates how to configure meta tag options within the nuxt.config.js file for the Nuxt PWA module. ```javascript pwa: { meta: { /* meta options */ } } ``` -------------------------------- ### Workbox Configuration Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/workbox.md Example of how to configure Workbox options within nuxt.config.js. This allows customization of Workbox behavior for Progressive Web Apps. ```js pwa: { workbox: { /* workbox options */ } } ``` -------------------------------- ### Nuxt PWA Manifest Configuration Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/manifest.md Example of how to configure the pwa.manifest options in nuxt.config.js to customize the Web App Manifest. This includes setting the app's name, language, and whether to use the webmanifest extension. ```js pwa: { manifest: { name: 'My Awesome App', lang: 'fa', useWebmanifestExtension: false } } ``` -------------------------------- ### Handle Update Notification Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/workbox.md Listens for the 'installed' event from Workbox to notify users about available updates. The logic inside the event listener can be customized to display a refresh prompt or perform other update-related actions. ```javascript const workbox = await window.$workbox; if (workbox) { workbox.addEventListener('installed', (event) => { // If we don't do this we'll be displaying the notification after the initial installation, which isn't perferred. if (event.isUpdate) { // whatever logic you want to use to notify the user that they need to refresh the page. } }); } ``` -------------------------------- ### Add PWA Module to Nuxt Config Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/setup.md Adds the '@nuxtjs/pwa' module to the buildModules section in the nuxt.config.js file. If using ssr: false in production without nuxt generate, use 'modules' instead of 'buildModules'. ```javascript { buildModules: [ '@nuxtjs/pwa', ] } ``` -------------------------------- ### Disable PWA Sub-module Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/setup.md Demonstrates how to disable a specific sub-module of the PWA module, such as the icon module, by setting its corresponding key to false in the pwa configuration object within nuxt.config.js. ```javascript { pwa: { icon: false // disables the icon module } } ``` -------------------------------- ### Ignore Service Worker Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/setup.md Adds service worker files to the .gitignore file to prevent them from being tracked by Git. ```ignore sw.* ``` -------------------------------- ### Web App Manifest Name vs. Short Name Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/manifest.md Explanation of the difference between the 'name' and 'short_name' properties in a Web App Manifest. 'name' is the primary identifier (max 45 chars) used in install dialogs and the Chrome Web Store, while 'short_name' is a shorter version (max 12 chars recommended) for home screens and new tab pages. ```APIDOC name: Description: The name (maximum of 45 characters) is the primary identifier of the app and is a required field. It is displayed in the install dialog, extension management UI, and Chrome Web Store. Source: https://developer.chrome.com/apps/manifest/name short_name: Description: 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 on device home screens and the New Tab page. Source: https://developer.chrome.com/apps/manifest/name ``` -------------------------------- ### Generate Static Site Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/README.md Creates the 'dist/' directory for publishing the Nuxt PWA Module to static hosting. ```bash yarn generate ``` -------------------------------- ### Workbox Options Documentation Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/workbox.md API documentation for Workbox module options in Nuxt. Covers general settings, precaching, runtime caching, and offline configurations. ```APIDOC Workbox Module Options: General: workboxVersion (String): Version of workbox. Default value is latest tested version. workboxURL (String): URL for workbox CDN. Default is JSDelivr. importScripts (Array): Additional scripts to be imported in service worker script. autoRegister (Boolean): Automatically register /sw.js on page load. Enabled by default. enabled (Boolean): Enable workbox module. Workbox is only enabled for production mode by default. Config: cacheNames (Object): Configure the workbox cache names. config (Object): Options to be passed to workbox before using it's modules. Default 'debug' field will be set to 'false' for production builds. clientsClaim (Boolean): Start controlling any existing clients as soon as it activates. Enabled by default. skipWaiting (Boolean): Skip over the SW waiting lifecycle stage. Enabled by default. offlineAnalytics (Boolean): Enable offline Google Analytics tracking. Disabled by default. workboxExtensions (String|String[]): Loads and inserts the contents of the specified file path into the service worker script before any call to precacheAndRoute. Precache: preCaching (Array): Cache a set of files when registering service worker. Default is []. cacheOptions (Object): Default cache options for precaching. cacheId: ' || nuxt' directoryIndex: '/' revision: undefined cachingExtensions (String|String[]): Loads and inserts the contents of the specified file path into the service worker script, below autogenerated calls to workbox.precaching.* cleanupOutdatedCaches (Boolean): Find and remove any of the older precaches that might have been used by previous versions of Workbox. Offline: offline (Boolean): Cache all routes. Enabled by default. offlineStrategy (String): Strategy for caching routes. Default is NetworkFirst. offlinePage (String): Enables routing all offline requests to the specified path. Example: '/offline.html'. offlineAssets (Array): List of assets to precache, in case you need extra files precached other than on the fly caching or you want to ensure assets used by your offlinePage. Example: ['/offline.png']. RuntimeCaching: runtimeCaching (Array): Custom routes to cache with specific strategy. Useful for caching requests to other origins. cacheAssets (Boolean): Cache requests to the /_nuxt/* with CacheFirst strategy on the fly. Enabled by default. ``` -------------------------------- ### Web App Manifest Specification Overview Source: https://github.com/nuxt-community/pwa-module/wiki/.webmanifest Provides an overview of the W3C working draft for web application manifests, detailing the purpose of metadata, icons, URLs, orientation, display mode, and scoping. ```APIDOC W3C Web App Manifest Specification: Purpose: Provides a centralized place for web application metadata. Key Features: - Application Name: The name of the web application. - Icons: Links to icons for the application. - Start URL: The preferred URL to open when the application is launched. - Orientation: Declares the default orientation for the application. - Display Mode: Sets the display mode (e.g., fullscreen). - Scope: Restricts the URLs to which the manifest applies and enables deep linking. File Extension Recommendation: `.webmanifest` (though not strictly required). Note: This document outlines the general specification and does not represent a specific implementation. ``` -------------------------------- ### Web App Manifest Default Options Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/manifest.md Documentation for the default options available for the Web App Manifest in the Nuxt PWA module. It details properties like name, short_name, description, icons, start_url, display, background_color, theme_color, dir, lang, useWebmanifestExtension, and publicPath, along with their types, defaults, and descriptions. ```APIDOC Web App Manifest Options: name (String): The primary identifier of the app (max 45 characters). Defaults to package.json's name property. short_name (String): A short version of the app's name (max 12 characters recommended). Defaults to package.json's name property. description (String): A description of the app. Defaults to package.json's description property. icons (Array): An array of icon objects. Defaults to []. start_url (String): The URL to load when the app is launched. Defaults to routerBase + '?standalone=true'. display (String): Determines how the app is displayed. Defaults to 'standalone'. background_color (String): The background color of the app. Defaults to '#ffffff'. theme_color (String): The theme color of the app. Defaults to pwa.meta.theme_color. dir (String): The text direction of the app ('ltr' or 'rtl'). Defaults to 'ltr'. lang (String): The language of the app. Defaults to 'en'. useWebmanifestExtension (Boolean): Whether to use the '.webmanifest' file extension. Defaults to false. publicPath (String): The public path for the manifest file. Defaults to a combination of routerBase and options.build.publicPath. ``` -------------------------------- ### Workbox Window Initialization Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/workbox.md Demonstrates how to access the Workbox instance after it has been registered in the background. This allows for interaction with the service worker once it's available. ```javascript const workbox = await window.$workbox if (workbox) { // Service worker is available } ``` -------------------------------- ### Icon Module Options Reference Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/icon.md Detailed reference for the options available to configure the PWA module's icon generation. Covers source, filenames, sizes, target directory, plugin integration, and purpose. ```APIDOC PwaIconModuleOptions: source: string - Default: `[srcDir]/[staticDir]/icon.png` - Description: Path to the source icon file. fileName: string - Default: `icon.png` - Description: The base filename for generated icons. sizes: number[] - Default: `[64, 120, 144, 152, 192, 384, 512]` - Description: An array of square sizes (in pixels) for the icons to be generated. targetDir: string - Default: `icons` - Description: The directory within the output path where generated icons will be placed. plugin: boolean - Default: `true` - Description: Whether to make icons accessible via `ctx` or Vue instances (e.g., `ctx.$icon(512)`). Returns an empty string if the size is not available. pluginName: string - Default: `'$icon'` - Description: The name of the property used to access icons via the plugin. purpose: string | string[] - Default: `['any', 'maskable']` - Description: Defines the purpose of the icons. Can be a single string or an array of strings. See https://w3c.github.io/manifest/#purpose-member for details. cacheDir: string - Default: `{rootDir}/node_modules/.cache/pwa/icon` - Description: Directory used for caching generated icons to improve build performance. ``` -------------------------------- ### Nuxt PWA Module Configuration Options Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/workbox.md Lists and describes various configuration options for the Nuxt PWA module, including routing extensions, asset and page URL patterns, service worker customization, and router base path. ```APIDOC `routingExtensions` (String|String[]): Loads and inserts the contents of the specified file path into the service worker script, below autogenerated calls to `workbox.routing.*`. You may add as many extra calls as you want to these files. `assetsURLPattern` (String/Regex): Pattern to match assets for runtime caching. Default is auto generated based on `publicPath`. Supports CDN too. Default: `/_nuxt/` `pagesURLPattern` (String/Regex): Pattern to match pages to be offlined. Default is auto generated based on `router.base`. Default: `/` `swTemplate` (String): You can use this to customize generated `sw.js`. Not recommended to be directly used. `swURL` (String): If you need to register another service worker (OneSignal, etc) you can use this option. `swDest` (String): If you want to change the name of service worker, you must use this option with swURL. `swScope` (String): Defaults to `routerBase`. `routerBase` (String): Defaults to router base. `publicPath` (String): Defaults to `/_nuxt`. ``` -------------------------------- ### Meta Module Options Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/meta.md Provides a comprehensive list of configuration options for the Nuxt PWA module's meta functionality, including default values and the corresponding meta tags they generate. ```APIDOC Meta Module Options: charset: - Default: "utf-8" - Description: Sets the character encoding for the document. viewport: - Default: "width=device-width, initial-scale=1" - Meta: "viewport" - Description: Configures the viewport for responsive design. mobileApp: - Default: true - Meta: "mobile-web-app-capable" - Description: Enables PWA capabilities for mobile browsers. mobileAppIOS: - Default: false - Meta: "apple-mobile-web-app-capable" - Description: Enables PWA capabilities for iOS devices. Requires careful consideration of Apple's guidelines. appleStatusBarStyle: - Default: "default" - Meta: "apple-mobile-web-app-status-bar-style" - Description: Controls the appearance of the status bar on iOS devices. Options: "default", "black", "black-translucent". favicon: - Default: true - Meta: "shortcut icon", "apple-touch-icon" - Description: Configures the favicon and Apple touch icon. Uses icons from the 'icon' module by default. name: - Default: *npm_package_name* - Meta: "title" - Description: Sets the title meta tag, typically derived from the npm package name. author: - Default: *npm_package_author_name* - Meta: "author" - Description: Sets the author meta tag, typically derived from the npm package author. description: - Default: *npm_package_description* - Meta: "description" - Description: Sets the description meta tag, typically derived from the npm package description. theme_color: - Default: undefined - Meta: "theme-color" - Description: Sets the theme color for the browser UI. lang: - Default: "en" - Meta: "lang" - Description: Sets the language attribute for the HTML tag. ogType: - Default: "website" - Meta: "og:type" - Description: Sets the Open Graph type. ogSiteName: - Default: same as options.name - Meta: "og:site_name" - Description: Sets the Open Graph site name. ogTitle: - Default: same as options.name - Meta: "og:title" - Description: Sets the Open Graph title. ogDescription: - Default: same as options.description - Meta: "og:description" - Description: Sets the Open Graph description. ogHost: - Default: undefined - Meta: "N/A" - Description: Specifies the domain for Open Graph image URLs. Required for ogImage. ogImage: - Default: true - Meta: "og:image" and sub-tags - Description: Configures Open Graph image meta tags. Accepts boolean (uses icons module), string (path), or object (path, width, height, type). ogUrl: - Default: ogHost (if defined) - Meta: "og:url" - Description: Sets the Open Graph URL. twitterCard: - Default: undefined - Meta: "twitter:card" - Description: Sets the Twitter card type. twitterSite: - Default: undefined - Meta: "twitter:site" - Description: Sets the Twitter site handle. twitterCreator: - Default: undefined - Meta: "twitter:creator" - Description: Sets the Twitter creator handle. nativeUI: - Default: false - Description: Enables native-looking UI enhancements for mobile apps. Modifies viewport and enables mobileAppIOS by default. ``` -------------------------------- ### Nuxt PWA Module Features Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/index.md This section outlines the core features provided by the Nuxt PWA Module. It details functionalities like service worker registration for offline caching, automatic manifest.json generation, SEO-friendly metadata integration, app icon generation, and push notification capabilities. ```javascript features: - Registers a service worker for offline caching. - Automatically generate manifest.json file. - Automatically adds SEO friendly meta data with manifest integration. - Automatically generates app icons with different sizes. - Free background push notifications using OneSignal. ``` -------------------------------- ### Light and Dark Mode Toggle Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/index.md Illustrates the usage of a color switcher component to toggle between light and dark modes within the Nuxt application, enhancing user experience. ```html

Enjoy light and dark mode: 

``` -------------------------------- ### Configure Icon Module Options Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/icon.md Configure the icon generation options for the Nuxt PWA module. This includes setting the source icon, desired sizes, output directory, and plugin behavior. ```javascript pwa: { icon: { /* icon options */ } } ``` -------------------------------- ### Runtime Caching for CDN Assets Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/workbox.md Configures runtime caching for assets served from a custom CDN. It specifies a URL pattern for matching CDN requests and suggests using 'NetworkFirst' or 'StaleWhileRevalidate' strategies for opaque responses. ```javascript workbox: { runtimeCaching: [ { // Should be a regex string. Compiles into new RegExp('https://my-cdn.com/.*') urlPattern: 'https://my-cdn.com/.*', // Defaults to `NetworkFirst` if omitted // handler: 'NetworkFirst', // Defaults to `GET` if omitted // method: 'GET' } ] } ``` -------------------------------- ### Configure Webmanifest Extension Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/manifest.md Sets the manifest file extension to `.json` or `.webmanifest`. This option enhances compatibility with various PWA configurations and browser interpretations of manifest files. ```javascript export default { pwa: { manifest: { // Set to '.webmanifest' to use that extension // Default is '.json' useWebmanifestExtension: true } } } ``` -------------------------------- ### Custom Cache Configuration with Strategy Plugins Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/workbox.md Sets up a custom cache named 'our-cache' for specific URL patterns, applying an 'Expiration' strategy plugin to limit cache entries and age. It also lists supported strategy plugins. ```javascript workbox: { runtimeCaching: [ { urlPattern: 'https://my-cdn.com/posts/.*', strategyOptions: { cacheName: 'our-cache', }, strategyPlugins: [{ use: 'Expiration', config: { maxEntries: 10, maxAgeSeconds: 300 } }] } ] } ``` -------------------------------- ### Basic Auth Workaround Configuration Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/workbox.md Enables the `crossorigin` attribute with 'use-credentials' for the manifest file, which is a workaround for making basic authentication work with PWAs as described in external resources. ```javascript { manifest: { crossorigin: 'use-credentials' } } ``` -------------------------------- ### Hooking into Service Worker Registration Lifecycle Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/workbox.md Provides a client-side plugin (`plugins/sw.client.js`) that logs information about registered service workers. This allows developers to interact with or monitor service worker registrations. ```javascript if ('serviceWorker' in navigator) { navigator.serviceWorker.getRegistrations().then((registrations) => { for (const worker of registrations) { console.log('Service worker:', worker) } }); } ``` ```javascript { plugins: [ '~/plugins/sw.client.js' ] } ``` -------------------------------- ### Enable Range Requests for Safari Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/workbox.md Configures Workbox to use Range Requests for media files (mp4, webm) to ensure compatibility with Safari. This involves registering a route with a CacheFirst strategy and the RangeRequestsPlugin. ```javascript workbox.routing.registerRoute( /\.(mp4|webm)/, new workbox.strategies.CacheFirst({ plugins: [ new workbox.rangeRequests.RangeRequestsPlugin(), ], }), 'GET' ); ``` ```js { workbox: { cachingExtensions: '@/plugins/workbox-range-request.js' } } ``` -------------------------------- ### Adding Custom Service Worker Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/workbox.md Demonstrates how to include a custom service worker script (`static/custom-sw.js`) by using the `importScripts` option in the Nuxt configuration. ```javascript workbox: { importScripts: [ 'custom-sw.js' ], } ``` -------------------------------- ### Disable Add to Home Screen Button Source: https://github.com/nuxt-community/pwa-module/blob/main/docs/content/en/workbox.md Prevents the 'Add to Home Screen' mini-infobar from appearing by setting the PWA manifest display mode to 'browser'. This is useful if the default display modes (fullscreen, standalone, minimal-ui) are not desired. ```js { pwa { manifest: { display: 'browser' } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.