Open avblink opened 3 years ago
Unfortunatelly, those didn't move/rename the file in dist folder. It stayed sw.js in the root of the dist folder
You can follow these steps:
static
dir, lets call it preview
swDest
to resolve('./static/preview/sw.js')
import { resolve } from 'path';
export default {
pwa: {
workbox: {
swDest: resolve('./static/preview/sw.js')
}
}
}
And you will see preview/sw.js
inside dist
Hi @farnabaz ,
thank you for taking the time to help me.
I think I was missing the 'resolve' bit. Now the file is in the right place, however, caching stopped working, i.e. the page is no longer accessible offline.
Lighthouse report shows 2 errors:
Does not register a service worker that controls page and start_url This origin has one or more service workers, however, the page (https://localhost/some/page/) is not in scope.
Here is my current config:
workbox: {
swDest: resolve('./static/ap-assets/sw.js'),
swURL: '/ap-assets/sw.js',
swScope: '/ap-assets/',
publicPath: '/ap-assets/',
},
I'm serving my nuxt generated folder behind nginx proxy on a sub url. (https://localhost/preview)
Need to serve sw.js from a subfolder, alternatively need to give it a different name so it can be easily differentiated by nginx proxy.
I tried with publicPath, but it still puts the sw.js file into the root of the dist folder.
Is there any way of achieving this?
Thank you in advance.