Open mmn6d6d6e opened 1 year ago
yeah any idea for this?
@mmn6d6d6e @vheins
The problem with PWA is about the scope and the location of the service worker and web manifest assets. Since vite-laravel-plugin
is hacking Vite to write all assets in public/build
folder we cannot hack Vite.
You have 2 solutions: 1) add custom http header
0.14.4
buildBase: '/build/'
to pwa configurationservice-worker-allowed: '/'
http header to all your router pages; requires some configuration on your backend (nginx, apache, netlify...)
2) create a Vite plugin:sw.js
, workbox-*.js
and manifest.webmanifest
to public folder: for sw.js
and workbox-*.js
you can try changing the outDir
to use public
folder, web manifest is emitted in Vite generateBundle
hook, and so Vite will generate it on public/build
foldermanifestTranform
to pwa workbox option to prefix any entry with build/
or using modifyURLPrefix: { '': 'build/' }
(also inside pwa workbox option).
I'm using laravel 9 The
index.html
is seved at/public
while the transpiled js files are at/public/build
By Laravel 9 Vite default setting the outDir is atpublic/build
and will always be cleaned whenvite build
is executedIf i left
outDir
by default:workbox-********.js
is generated on/public/build
, good. It'll automatically cleaned on each buildsw.js
is also generated on/public/build
, not good. This is causing errorThe path of the provided scope ('/public') is not under the max scope allowed ('/public/build/'). Adjust the scope, move the Service Worker script, or use the Service-Worker-Allowed HTTP header to allow the scope.
and I'd rather not change web service settings to setService-Worker-Allowed HTTP
headerIf i change the
outDir
topublic
:sw.js
is generated on/public
, good. No max scope error.workbox-********.js
is also generated on/public
, not good. the old one need to be manually cleaned if newer one have different hash, or need additional plugin to clean it each buildThe ideal scenario I had in my mind:
workbox-********.js
to/public/build
so it will be cleaned on eachvite build
with Laravel 9 default settingsw.js
to/public
and it load/public/build/workbox-********.js
Is it possible? or is there alternative way with both no max scope allowed error neither piling up
workbox-********.js
files?