Skip to content

Instantly share code, notes, and snippets.

@cristoni
Last active November 16, 2018 20:07
Show Gist options
  • Save cristoni/57b0cf6584f548d1c3001f479266c9fb to your computer and use it in GitHub Desktop.
Save cristoni/57b0cf6584f548d1c3001f479266c9fb to your computer and use it in GitHub Desktop.
Esempio di nextjs config file con sass, compose e offline
const compose = require('next-compose');
const withSass = require('@zeit/next-sass');
const { InjectManifest } = require('workbox-webpack-plugin');
module.exports = compose([
[withSass],
{
webpack: config => {
const swOptions = {
swSrc: 'C:/Sviluppo/react/ui-eventi/service-worker.js',
};
return {
...config,
plugins: [
...config.plugins,
new InjectManifest(swOptions)
]
};
}
}
]);
@cristoni
Copy link
Author

cristoni commented Nov 15, 2018

Rimosso utilizzo di next-offline in favore dell'utilizzo diretto di workbox-webpack-plugin con InjectManifest invece di GenerateSW.

Aggiunto a server.js:
server.get('/precache-manifest*', (req, res) => { const filePath = join(__dirname, '.next', req.url); app.serveStatic(req, res, filePath); })

@cristoni
Copy link
Author

cristoni commented Nov 15, 2018

Per il service-worker.js di esempio controllare https://gist.github.com/cristoni/daf391f9a3354e7579c373d762ef5cd4

@realtebo
Copy link

Condivido questo suggerimento

server.get("/service-worker.js", (req, res) => {
  // Don't cache service worker is a best practice (otherwise clients wont get emergency bug fix)
  res.set("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate");
  res.set("Content-Type", "application/javascript");
  const filePath = join(__dirname, '.next', req.url);
  app.serveStatic(req, res, filePath);
});

https://gist.github.com/realtebo/43edd8a1b23b325e2d87290d080a0003

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment