Last active
November 16, 2018 20:07
-
-
Save cristoni/57b0cf6584f548d1c3001f479266c9fb to your computer and use it in GitHub Desktop.
Esempio di nextjs config file con sass, compose e offline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
] | |
}; | |
} | |
} | |
]); |
Per il service-worker.js di esempio controllare https://gist.github.com/cristoni/daf391f9a3354e7579c373d762ef5cd4
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
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); })