0Pricing
Vue Academy · Lesson

vite-plugin-pwa Setup

Plugin configuration, manifest options, icons, screenshots, display modes, scope.

vite-plugin-pwa Setup is a free Vue Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What is a PWA

A Progressive Web App adds installability, offline support, and native-like features to a web app via a service worker and a web app manifest. vite-plugin-pwa automates wiring both into a Vue + Vite build.

Installing the Plugin

Install vite-plugin-pwa as a dev dependency. It uses Workbox under the hood to generate the service worker.

npm install -D vite-plugin-pwa

Adding VitePWA to Plugins

Import VitePWA and add it to the Vite plugins array. Options are passed to its single function call.

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { VitePWA } from "vite-plugin-pwa";

export default defineConfig({
  plugins: [vue(), VitePWA({ /* options */ })]
});

registerType

registerType controls update behavior. "autoUpdate" activates new service workers immediately; "prompt" lets you ask the user before reloading.

VitePWA({
  registerType: "autoUpdate"
});

The manifest Options

The manifest object becomes the web app manifest. Key fields are name, short_name, theme_color, and icons.

VitePWA({
  manifest: {
    name: "My Vue App",
    short_name: "VueApp",
    theme_color: "#42b883"
  }
});

The icons Array

Provide multiple icon sizes so the OS can pick the right one for the home screen and splash. Include a maskable icon for adaptive shapes.

manifest: {
  icons: [
    { src: "/pwa-192.png", sizes: "192x192", type: "image/png" },
    { src: "/pwa-512.png", sizes: "512x512", type: "image/png" },
    { src: "/maskable.png", sizes: "512x512", type: "image/png", purpose: "maskable" }
  ]
}

Workbox Configuration

The workbox option configures the generated service worker - which files to precache and any runtime caching rules.

VitePWA({
  workbox: {
    globPatterns: ["**/*.{js,css,html,png,svg}"]
  }
});

injectRegister auto

injectRegister: "auto" automatically injects the code that registers the service worker, so you do not hand-write registration logic.

VitePWA({
  registerType: "autoUpdate",
  injectRegister: "auto"
});

Using the Virtual Register Module

For prompt-based updates, import the virtual registerSW module in your entry file and hook into its callbacks.

import { registerSW } from "virtual:pwa-register";

const updateSW = registerSW({
  onNeedRefresh() { /* show update toast */ },
  onOfflineReady() { /* show ready toast */ }
});

Enabling in Development

By default the service worker only runs in production. Enable devOptions to test PWA behavior during development.

VitePWA({
  devOptions: { enabled: true }
});

Verifying the Install

After building and serving, open Chrome DevTools Application tab. You should see the manifest parsed, an active service worker, and an install prompt available in the address bar.

Quick Check

What does injectRegister: "auto" do?

Recap

Add VitePWA to the Vite plugins array with a registerType (autoUpdate or prompt), a manifest (name, short_name, theme_color, icons array), and workbox options. Use injectRegister: "auto" for automatic service worker registration, or the virtual:pwa-register module for prompt-based updates.

Frequently asked questions

Is the “vite-plugin-pwa Setup” lesson free?

Yes — the full text of “vite-plugin-pwa Setup” is free to read here on the web, and the Vue Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Vue Academy course, upgrade to CoddyKit PRO.

What will I learn in “vite-plugin-pwa Setup”?

Plugin configuration, manifest options, icons, screenshots, display modes, scope. You practise Vue Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Vue Academy?

No prior experience is required. Vue Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “vite-plugin-pwa Setup” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Vue Academy lesson?

Yes. Every Vue Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. vite-plugin-pwa Setup
  2. Service Worker Strategies
  3. Offline Support and Background Sync
  4. Push Notifications in Vue PWA
← Back to Vue Academy