Socket
Socket
Sign inDemoInstall

vite-plugin-pwa

Package Overview
Dependencies
7
Maintainers
3
Versions
120
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-pwa


Version published
Weekly downloads
287K
decreased by-9.52%
Maintainers
3
Install size
41.2 MB
Created
Weekly downloads
ย 

Package description

What is vite-plugin-pwa?

vite-plugin-pwa is a plugin for Vite that enables Progressive Web App (PWA) functionalities. It helps in generating service workers, manifest files, and other PWA-related configurations to make your web application installable and offline-capable.

What are vite-plugin-pwa's main functionalities?

Generate Service Worker

This feature allows you to generate a service worker with runtime caching strategies. The code sample demonstrates how to cache image files using a 'CacheFirst' strategy.

```javascript
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';

export default defineConfig({
  plugins: [
    VitePWA({
      registerType: 'autoUpdate',
      workbox: {
        runtimeCaching: [
          {
            urlPattern: /\.(?:png|jpg|jpeg|svg|gif)$/, 
            handler: 'CacheFirst',
            options: {
              cacheName: 'images',
              expiration: {
                maxEntries: 10,
              },
            },
          },
        ],
      },
    }),
  ],
});
```

Generate Manifest File

This feature allows you to generate a web app manifest file. The code sample shows how to configure the manifest with app name, description, theme color, and icons.

```javascript
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';

export default defineConfig({
  plugins: [
    VitePWA({
      manifest: {
        name: 'My App',
        short_name: 'App',
        description: 'My awesome app',
        theme_color: '#ffffff',
        icons: [
          {
            src: 'icon-192x192.png',
            sizes: '192x192',
            type: 'image/png',
          },
          {
            src: 'icon-512x512.png',
            sizes: '512x512',
            type: 'image/png',
          },
        ],
      },
    }),
  ],
});
```

Auto Update Service Worker

This feature enables the service worker to automatically update when new content is available. The code sample shows how to set the 'registerType' to 'autoUpdate'.

```javascript
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';

export default defineConfig({
  plugins: [
    VitePWA({
      registerType: 'autoUpdate',
    }),
  ],
});
```

Other packages similar to vite-plugin-pwa

Readme

Source

vite-plugin-pwa - Zero-config PWA for Vite
Zero-config PWA Framework-agnostic Plugin for Vite

NPM version NPM Downloads Docs & Guides
GitHub stars


๐Ÿš€ Features

  • ๐Ÿ“– Documentation & guides
  • ๐Ÿ‘Œ Zero-Config: sensible built-in default configs for common use cases
  • ๐Ÿ”ฉ Extensible: expose the full ability to customize the behavior of the plugin
  • ๐Ÿฆพ Type Strong: written in TypeScript
  • ๐Ÿ”Œ Offline Support: generate service worker with offline support (via Workbox)
  • โšก Fully tree shakable: auto inject Web App Manifest
  • ๐Ÿ’ฌ Prompt for new content: built-in support for Vanilla JavaScript, Vue 3, React, Svelte, SolidJS and Preact
  • โš™๏ธ Stale-while-revalidate: automatic reload when new content is available
  • โœจ Static assets handling: configure static assets for offline support
  • ๐Ÿž Development Support: debug your custom service worker logic as you develop your application
  • ๐Ÿ› ๏ธ Versatile: integration with meta frameworks: รฎles, SvelteKit, VitePress, Astro, Nuxt 3 and Remix
  • ๐Ÿ’ฅ PWA Assets Generator: generate all the PWA assets from a single command and a single source image
  • ๐Ÿš€ PWA Assets Integration: serving, generating and injecting PWA Assets on the fly in your application

๐Ÿ“ฆ Install

From v0.17, vite-plugin-pwa requires Vite 5.

From v0.16 vite-plugin-pwa requires Node 16 or above: workbox v7 requires Node 16 or above.

From v0.13, vite-plugin-pwa requires Vite 3.1 or above.

npm i vite-plugin-pwa -D 

# yarn 
yarn add vite-plugin-pwa -D

# pnpm 
pnpm add vite-plugin-pwa -D

๐Ÿฆ„ Usage

Add VitePWA plugin to vite.config.js / vite.config.ts and configure it:

// vite.config.js / vite.config.ts
import { VitePWA } from 'vite-plugin-pwa'

export default {
  plugins: [
    VitePWA()
  ]
}

Read the ๐Ÿ“– documentation for a complete guide on how to configure and use this plugin.

Check out the client type declarations client.d.ts for built-in frameworks support.

๐Ÿ‘€ Full config

Check out the type declaration src/types.ts and the following links for more details.

๐Ÿ“„ License

MIT License ยฉ 2020-PRESENT Anthony Fu

Keywords

FAQs

Last updated on 05 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc