fix: fix broken CSP in dev mode (#992)
It seems #988 occasionally breaks dev mode due to missing SW script. This fixes that.
This commit is contained in:
parent
1b9d3b1cd0
commit
75db2c0dac
|
@ -4,17 +4,19 @@
|
||||||
|
|
||||||
import crypto from 'crypto'
|
import crypto from 'crypto'
|
||||||
|
|
||||||
let scripts = [
|
const baseScripts = [
|
||||||
`__SAPPER__={baseUrl:"",preloaded:[{},{}]};`,
|
`__SAPPER__={baseUrl:"",preloaded:[{},{}]};`,
|
||||||
`__SAPPER__={baseUrl:"",preloaded:[{}]};`,
|
`__SAPPER__={baseUrl:"",preloaded:[{}]};`,
|
||||||
`__SAPPER__={baseUrl:"",preloaded:[{},null,null,{}]};`,
|
`__SAPPER__={baseUrl:"",preloaded:[{},null,null,{}]};`,
|
||||||
`__SAPPER__={baseUrl:"",preloaded:[{},null,{}]};`
|
`__SAPPER__={baseUrl:"",preloaded:[{},null,{}]};`
|
||||||
]
|
]
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'production') {
|
const scriptsWithSW = baseScripts.map(script => (
|
||||||
// sapper adds service worker only in production
|
`${script}if('serviceWorker' in navigator)navigator.serviceWorker.register('/service-worker.js');`)
|
||||||
scripts = scripts.map(script => `${script}if('serviceWorker' in navigator)navigator.serviceWorker.register('/service-worker.js');`)
|
)
|
||||||
}
|
|
||||||
|
// sapper adds service worker usually, but it seems inconsistent in dev mode especially
|
||||||
|
const scripts = [].concat(baseScripts).concat(scriptsWithSW)
|
||||||
|
|
||||||
export const sapperInlineScriptChecksums = scripts.map(script => {
|
export const sapperInlineScriptChecksums = scripts.map(script => {
|
||||||
return crypto.createHash('sha256').update(script).digest('base64')
|
return crypto.createHash('sha256').update(script).digest('base64')
|
||||||
|
|
Loading…
Reference in a new issue