Pinafore-Web-Client-Frontend/src/server/sapperInlineScriptChecksums.js

24 lines
945 B
JavaScript
Raw Permalink Normal View History

// TODO: this is a hacky solution to generating checksums for Sapper's inline scripts.
// I determined this by running `sapper export` and then checking all unique inline scripts.
// Really, this ought to be built into Sapper somehow.
import crypto from 'crypto'
const baseScripts = [
2019-08-20 04:08:59 +02:00
'__SAPPER__={baseUrl:"",preloaded:[{},{}]};',
'__SAPPER__={baseUrl:"",preloaded:[{}]};',
'__SAPPER__={baseUrl:"",preloaded:[{},null,null,{}]};',
'__SAPPER__={baseUrl:"",preloaded:[{},null,{}]};'
]
const scriptsWithSW = baseScripts.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 => {
2021-03-07 17:21:20 +01:00
return crypto.createHash('sha256').update(script, 'utf8').digest('base64')
})