Sakai Vue is a modern, responsive dashboard application built with Vue.js and Vite. This project has been converted into a Progressive Web App (PWA), making it installable, offline-capable, and providing an app-like experience on desktop and mobile devices.
A PWA is a web application that uses modern browser features to deliver a native app-like experience. Key benefits include:
- Installability: Users can add the app to their home screen or desktop.
- Offline Support: The app works without an internet connection.
- Native Experience: Standalone window, custom icon, and splash screen.
- Performance: Faster load times via caching.
- The Sakai Vue app is now a fully functional PWA.
- Users can install the app on desktop or mobile and use it offline.
- The PWA setup is robust, using industry best practices and automated tooling.
The PWA functionality is powered by the vite-plugin-pwa
plugin, which automates the creation and management of the service worker and manifest.
- Development:
- A basic service worker is provided for installability.
- Production Build:
- When you run
npm run build
, Vite outputs all static files. - The plugin scans the output, finds all files to cache, and generates a service worker with:
- The list of files to cache (with hashed names)
- Caching and update logic
- The service worker is automatically registered in your app.
- When you run
flowchart TD
A[Run npm run build] --> B[Vite builds static files]
B --> C[vite-plugin-pwa scans output]
C --> D[Generates service worker with file list & logic]
D --> E[Service worker registered in app]
E --> F[App works offline & updates automatically]
- A static service worker in
public/
cannot track file changes or hashed filenames after each build. - The plugin ensures the service worker is always up-to-date and reliable.
To enable PWA features, the following changes were made:
- PWA Dependency Installed
- Added
vite-plugin-pwa
as a dev dependency:npm install vite-plugin-pwa --save-dev
- Added
- Manifest Configuration
- Created
public/manifest.json
(for development and fallback):{ "name": "Sakai Vue App", "short_name": "Sakai", "description": "A modern Vue.js dashboard app.", "start_url": ".", "display": "standalone", "background_color": "#ffffff", "theme_color": "#0d6efd", "icons": [ { "src": "/demo/images/logo.svg", "sizes": "192x192", "type": "image/svg+xml" }, { "src": "/demo/images/logo.svg", "sizes": "512x512", "type": "image/svg+xml" } ] }
- Also configured the manifest in
vite.config.mjs
for production builds (plugin-managed):import { VitePWA } from 'vite-plugin-pwa'; // ... plugins: [ // ... VitePWA({ registerType: 'autoUpdate', manifest: { name: 'Sakai Vue App', short_name: 'Sakai', description: 'A modern Vue.js dashboard app.', start_url: '.', display: 'standalone', background_color: '#ffffff', theme_color: '#0d6efd', icons: [ { src: '/demo/images/logo.svg', sizes: '192x192', type: 'image/svg+xml' }, { src: '/demo/images/logo.svg', sizes: '512x512', type: 'image/svg+xml' } ] } }) ];
- Created
- HTML Head Update
- Added manifest and theme color to
index.html
:<link rel="manifest" href="/manifest.json" /> <meta name="theme-color" content="#0d6efd" />
- Added manifest and theme color to
- Install dependencies:
npm install
- Run in development:
Open http://localhost:5173 in your browser.
npm run dev
- Build for production:
npm run build npm run preview
- Test PWA features:
- Open the app in Chrome, Edge, or another PWA-supporting browser.
- Look for the install prompt in the address bar or browser menu.
- Click to install the app to your desktop or mobile device.
- The app will work offline after the first load.
vite-plugin-pwa
– Handles service worker and manifest generation for Vite projects.
src/ # Vue components, views, and layout
public/manifest.json # Web app manifest for PWA
public/demo/images/ # App icons and images
vite.config.mjs # Vite configuration with PWA plugin
index.html # HTML entry point
public/manifest.json
is used for development and as a fallback.- The manifest in
vite.config.mjs
is used by the plugin to generate a production-ready manifest and ensure it matches the service worker. - This approach guarantees your PWA is always up-to-date and reliable.
File/Config | Used For | When Used | Who Uses It |
---|---|---|---|
public/manifest.json |
Static manifest | Dev & fallback | Browser |
vite.config.mjs manifest |
Dynamic, plugin-managed | Build/Production | Vite PWA plugin |
How to use and test the delivered PWA feature:
- The application is now installable as a PWA. To test:
- Run
npm run dev
(for development) ornpm run preview
(for production build preview). - Open the app in a browser like Chrome or Edge.
- You should see an install prompt in the address bar or browser menu.
- Click to install the app to your desktop or mobile device.
- The app will work offline after the first load.
- Run
This project is licensed under the MIT License. See LICENSE.md for details.