CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-nuxtjs--pwa

Zero config PWA solution for Nuxt.js applications with service worker management, manifest generation, and meta tag optimization

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

@nuxtjs/pwa

@nuxtjs/pwa is a comprehensive Progressive Web App solution for Nuxt.js applications providing zero-configuration PWA setup. It integrates service worker management through Workbox, web app manifest generation, meta tag optimization, and automatic icon generation to transform regular Nuxt.js applications into full-featured PWAs with offline support, installability, and performance optimizations.

Package Information

  • Package Name: @nuxtjs/pwa
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @nuxtjs/pwa

Core Imports

Since this is a Nuxt.js module, it's configured in the Nuxt configuration rather than imported directly:

// nuxt.config.ts
export default {
  modules: ['@nuxtjs/pwa'],
  pwa: {
    // PWA configuration options
  }
}

For accessing generated runtime functionality:

// In Vue components or plugins
this.$icon('192x192'); // Access generated icons

Basic Usage

// nuxt.config.ts
export default {
  modules: ['@nuxtjs/pwa'],
  pwa: {
    meta: {
      name: 'My PWA App',
      description: 'A progressive web application',
      theme_color: '#2196f3'
    },
    manifest: {
      name: 'My PWA App',
      short_name: 'PWA App',
      background_color: '#ffffff'
    },
    workbox: {
      offline: true,
      cacheAssets: true
    },
    icon: {
      sizes: [64, 120, 144, 152, 192, 384, 512]
    }
  }
}

Architecture

@nuxtjs/pwa is structured around four main sub-modules:

  • PWA Module: Main orchestrator that coordinates all sub-modules during Nuxt.js build process
  • Icon Module: Handles automatic icon generation and resizing for different device requirements
  • Manifest Module: Generates web app manifest files with PWA metadata and configuration
  • Meta Module: Manages HTML meta tags for PWA compliance, SEO, and social media optimization
  • Workbox Module: Integrates Workbox for service worker management, caching strategies, and offline functionality

Capabilities

PWA Module Configuration

Main module configuration interface for coordinating PWA setup across all sub-modules.

interface PWAOptions {
  meta?: Partial<MetaOptions> | false;
  icon?: Partial<IconOptions> | false;
  workbox?: Partial<WorkboxOptions> | false;
  manifest?: Partial<ManifestOptions> | false;
}

/**
 * Main PWA module function that coordinates all sub-modules
 * @param moduleOptions - Configuration options for PWA sub-modules
 * @returns Promise that resolves when all modules are initialized
 */
export default async function pwa(moduleOptions: PWAOptions): Promise<void>;

PWA Module

Icon Generation

Automatic icon generation and resizing from a source image for various device sizes and iOS splash screens.

interface IconOptions {
  source: string;
  fileName: string;
  sizes: number[];
  iosSizes: [number, number, string][];
  targetDir: string;
  plugin: boolean;
  pluginName: string;
  purpose: string[] | string;
  cacheDir: string;
  publicPath: string;
}

Icon Generation

Manifest Generation

Web app manifest generation with customizable PWA metadata and configuration options.

interface ManifestOptions {
  name: string;
  short_name: string;
  description: string;
  icons: Record<string, any>[];
  start_url: string;
  display: string;
  background_color: string;
  theme_color: string;
  dir: 'ltr' | 'rtl';
  lang: string;
  useWebmanifestExtension: boolean;
  publicPath: string;
  fileName: string;
  crossorigin: boolean;
}

Manifest Generation

Meta Tag Management

HTML meta tag generation for PWA compliance, SEO optimization, and social media integration.

interface MetaOptions extends Partial<ManifestOptions> {
  charset: string;
  viewport: string;
  mobileApp: boolean;
  mobileAppIOS: boolean;
  appleStatusBarStyle: string;
  favicon: boolean;
  name: string;
  title?: string;
  author: string;
  description: string;
  theme_color: string;
  lang: string;
  ogType: string;
  ogSiteName: string | true;
  ogTitle: string | true;
  ogDescription: string | true;
  ogHost: string | undefined;
  ogImage: boolean | string | OgImageObject;
  ogUrl: string | undefined | true;
  twitterCard: string | undefined;
  twitterSite: string | undefined;
  twitterCreator: string | undefined;
  nativeUI: boolean;
}

interface OgImageObject {
  path?: string;
  width?: number;
  height?: number;
  type?: string;
}

Meta Tag Management

Service Worker & Caching

Workbox integration for service worker management, caching strategies, and offline functionality.

interface WorkboxOptions {
  dev: boolean;
  workboxVersion: string;
  workboxURL: string;
  importScripts: string[];
  autoRegister: boolean;
  enabled: boolean;
  cacheNames: Record<string, any>;
  config: Record<string, any>;
  clientsClaim: boolean;
  skipWaiting: boolean;
  offlineAnalytics: boolean;
  workboxExtensions: string | string[];
  preCaching: string[] | {url: string, revision: string}[];
  cacheOptions: CacheOptions;
  cachingExtensions: string | string[];
  cleanupOutdatedCaches: boolean;
  offline: boolean;
  offlineStrategy: CachingStrategy;
  offlinePage: string;
  offlineAssets: string[];
  runtimeCaching: RuntimeCaching[];
  cacheAssets: boolean;
  routingExtensions: string | string[];
  assetsURLPattern: string;
  pagesURLPattern: string;
  swTemplate: string;
  swURL: string;
  swDest: string;
  swScope: string;
  routerBase: string;
  publicPath: string;
}

interface CacheOptions {
  cacheId: string;
  directoryIndex: string;
  revision: string | undefined;
}

interface RuntimeCaching {
  urlPattern: string;
  handler?: CachingStrategy;
  method?: HTTPMethod;
  strategyOptions?: StrategyOptions;
  strategyPlugins?: StrategyPlugin[];
}

type CachingStrategy = 'CacheFirst' | 'CacheOnly' | 'NetworkFirst' | 'NetworkOnly' | 'StaleWhileRevalidate';

type HTTPMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';

interface StrategyOptions {
  cacheName?: string;
  plugins?: any[];
  networkTimeoutSeconds?: number;
  ignoreVary?: boolean;
  cacheKeyWillBeUsed?: boolean;
  cacheWillUpdate?: boolean;
  fetchDidSucceed?: boolean;
  requestWillFetch?: boolean;
}

Service Worker & Caching

Core Utilities

URL Utilities

URL manipulation and path handling utilities used throughout the PWA module.

/**
 * Check if a URL is absolute (starts with http/https or //)
 * @param url - URL string to check
 * @returns True if URL is absolute
 */
function isUrl(url: string): boolean;

/**
 * Join URL paths with proper handling of protocol separators
 * @param args - URL path segments to join
 * @returns Joined URL path
 */
function joinUrl(...args: string[]): string;

/**
 * Extract router base and public path from Nuxt options
 * @param options - Nuxt configuration options
 * @returns Object containing routerBase and publicPath
 */
function getRouteParams(options: any): { routerBase: string; publicPath: string };

Size and String Utilities

Utilities for icon size normalization and string manipulation.

/**
 * Normalize size array to ensure consistent [width, height] format
 * @param size - Size as number, array, or undefined
 * @returns Normalized [width, height] size array
 */
function normalizeSize(size: number | [number, number] | []): [number, number];

/**
 * Generate size name string from size array
 * @param size - Size array (supports third element for prefix)
 * @returns Size name in format "prefix_WxH" or "WxH"
 */
function sizeName(size: number | [number, number] | [number, number, string]): string;

/**
 * Convert string to start case (first letter uppercase)
 * @param str - String to convert
 * @returns String with first letter capitalized
 */
function startCase(str: string): string;

File and Asset Utilities

File system and asset management utilities.

/**
 * Emit asset to build directory during build process
 * @param nuxt - Nuxt instance
 * @param fileName - Target file name
 * @param data - File content or Promise that resolves to content
 */
function emitAsset(nuxt: any, fileName: string, data: string | Promise<string>): void;

/**
 * Write data to file with directory creation
 * @param path - Target file path
 * @param data - Data to write or Promise that resolves to data
 */
async function writeData(path: string, data: string | Promise<string>): Promise<void>;

/**
 * Read and concatenate JavaScript files
 * @param nuxt - Nuxt instance
 * @param files - File path or array of file paths
 * @returns Concatenated file contents
 */
async function readJSFiles(nuxt: any, files: string | string[]): Promise<string>;

/**
 * Copy template file with variable substitution
 * @param options - Template copy options
 */
async function copyTemplate(options: { src: string; dst: string; options: any }): Promise<void>;

Object and Meta Utilities

Object manipulation and meta tag handling utilities.

/**
 * Pick specific properties from an object
 * @param obj - Source object
 * @param props - Array of property names to pick
 * @returns New object with selected properties
 */
function pick(obj: Record<string, any>, props: string[]): Record<string, any>;

/**
 * Generate random string of specified length
 * @param length - Desired string length
 * @returns Random alphanumeric string
 */
function randomString(length: number): string;

/**
 * Merge meta object arrays with deduplication
 * @param to - Target meta object
 * @param from - Source meta object to merge
 */
function mergeMeta(to: Record<string, any>, from: Record<string, any>): void;

Types

Core Context Interface

interface PWAContext {
  meta?: MetaOptions;
  icon?: IconOptions;
  workbox?: WorkboxOptions;
  manifest?: ManifestOptions;
  _manifestMeta: any;
}

iOS Device Types

type iOSType = 'ipad' | 'ipadpro9' | 'ipadpro10' | 'ipadpro12' | 'iphonese' | 'iphone6' | 'iphoneplus' | 'iphonex' | 'iphonexr' | 'iphonexsmax';

type iOSSize = [number, number, iOSType];

Strategy Plugin Types

type StrategyPlugin = BackgroundSync | BroadcastUpdate | CacheableResponse | Expiration | RangeRequests;

interface BackgroundSync {
  use: 'BackgroundSync';
  config: any;
}

interface BroadcastUpdate {
  use: 'BroadcastUpdate';
  config: any;
}

interface CacheableResponse {
  use: 'CacheableResponse';
  config: any;
}

interface Expiration {
  use: 'Expiration';
  config: any;
}

interface RangeRequests {
  use: 'RangeRequests';
  config: any;
}

Install with Tessl CLI

npx tessl i tessl/npm-nuxtjs--pwa
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@nuxtjs/pwa@3.3.x
Publish Source
CLI
Badge
tessl/npm-nuxtjs--pwa badge