Skip to content

How to separate output path for sw.js and workbox-********.js #467

@mmn6d6d6e

Description

@mmn6d6d6e

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 at public/build and will always be cleaned when vite build is executed

If i left outDir by default:

  • the workbox-********.js is generated on /public/build, good. It'll automatically cleaned on each build
  • the sw.js is also generated on /public/build, not good. This is causing error The 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 set Service-Worker-Allowed HTTP header

If i change the outDir to public:

  • the sw.js is generated on /public, good. No max scope error.
  • the 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 build

The ideal scenario I had in my mind:

  • generate workbox-********.js to /public/build so it will be cleaned on each vite build with Laravel 9 default setting
  • generate sw.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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions