vincent15000's avatar

Laravel / VueJS PWA

Hello,

I have a Laravel / VueJS application and I want to have a PWA.

I have already done this with the silviolleite/laravelpwa package for pure Laravel applications, but the package is not appropriated for VueJS.

Who has already done a PWA with VueJS and how did you do ?

I just tried for some hours to use the vite-plugin-pwa plugin, several tutorials show how to use it, but nothing works as expected for me ... the tutorials are with a pure VueJS application, but I have a Laravel / VueJS application.

Any idea ?

Thanks for your help.

V

0 likes
3 replies
vincent15000's avatar
vincent15000
OP
Best Answer
Level 63

I just found the solution with this configuration with the vite-plugin-pwa.

1 like
martinbean's avatar

@vincent15000 It completely depends what PWA features you’re actually wanting to implement for your app.

PWAs are mainly based around a service worker. These are completely library- and framework-agnostic. They’re just JavaScript files.

1 like
LaryAI's avatar
Level 58

Certainly! Here’s how you can set up a PWA in a Laravel + Vue 3 (with Vite) application using the vite-plugin-pwa package.

1. Install the Plugin

First, install the plugin in your Laravel project (inside the resources/js directory if you keep your frontend assets there):

npm install vite-plugin-pwa --save-dev

2. Configure Vite

Open your vite.config.js (or vite.config.ts if using TypeScript) in the root of your Laravel project and add the PWA plugin:

Note: Place your icon files (icon-192x192.png, icon-512x512.png) in the public directory.

3. Register the Service Worker in Vue

In your main Vue entry file (e.g., resources/js/app.js or main.js), add:

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

registerSW();

4. Build and Test

Run your development server:

npm run dev

Or build for production:

npm run build

Then, serve your Laravel app (e.g., php artisan serve) and visit it in your browser. You should see the PWA install prompt and be able to use it offline.

5. Troubleshooting

  • Make sure your icons are accessible at /icon-192x192.png and /icon-512x512.png.
  • Clear your browser cache or use a private window if you’re not seeing updates.
  • Check the browser console for service worker errors.

Summary:
You don’t need to use silviolleite/laravelpwa for Vue. Instead, use vite-plugin-pwa directly in your Vite config, and register the service worker in your Vue app. This approach works seamlessly with Laravel + Vue + Vite.

Let me know if you need a more detailed step-by-step or run into any issues!

Please or to participate in this conversation.