nuxt-community / pwa-module

Zero config PWA solution for Nuxt.js
https://pwa.nuxtjs.org
MIT License
1.23k stars 171 forks source link

QUESTION - With nuxt generate, can I put sw.js file into a subdirectory? #440

Open avblink opened 3 years ago

avblink commented 3 years ago

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.

farnabaz commented 3 years ago

There is two options, swDest and swURL in the docs that might help you.

avblink commented 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

farnabaz commented 3 years ago

You can follow these steps:

import { resolve } from 'path';

export default {
  pwa: {
    workbox: {
      swDest: resolve('./static/preview/sw.js')
    }
  }
}

And you will see preview/sw.js inside dist

avblink commented 3 years ago

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: