chore: move inline-script to src (#917)
This commit is contained in:
parent
eb5437e32a
commit
d976b621b8
|
@ -8,4 +8,4 @@ node_modules
|
|||
/static/robots.txt
|
||||
/static/inline-script.js.map
|
||||
/static/emoji-mart-all.json
|
||||
/inline-script-checksum.json
|
||||
/src/inline-script/checksum.js
|
||||
|
|
|
@ -13,7 +13,7 @@ const writeFile = promisify(fs.writeFile)
|
|||
const themeColors = fromPairs(themes.map(_ => ([_.name, _.color])))
|
||||
|
||||
export async function buildInlineScript () {
|
||||
let inlineScriptPath = path.join(__dirname, '../inline-script.js')
|
||||
let inlineScriptPath = path.join(__dirname, '../src/inline-script/inline-script.js')
|
||||
|
||||
let bundle = await rollup({
|
||||
input: inlineScriptPath,
|
||||
|
@ -38,8 +38,8 @@ export async function buildInlineScript () {
|
|||
let fullCode = `${code}//# sourceMappingURL=/inline-script.js.map`
|
||||
let checksum = crypto.createHash('sha256').update(fullCode).digest('base64')
|
||||
|
||||
await writeFile(path.resolve(__dirname, '../inline-script-checksum.json'),
|
||||
JSON.stringify({ checksum }), 'utf8')
|
||||
await writeFile(path.resolve(__dirname, '../src/inline-script/checksum.js'),
|
||||
`module.exports = ${JSON.stringify(checksum)}`, 'utf8')
|
||||
await writeFile(path.resolve(__dirname, '../static/inline-script.js.map'),
|
||||
map.toString(), 'utf8')
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ const builders = [
|
|||
rebuild: buildSass
|
||||
},
|
||||
{
|
||||
watch: 'inline-script.js',
|
||||
watch: 'src/inline-script/inline-script.js',
|
||||
comment: '<!-- inline JS -->',
|
||||
rebuild: buildInlineScript
|
||||
},
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
// For perf reasons, this script is run inline to quickly set certain styles.
|
||||
// To allow CSP to work correctly, we also calculate a sha256 hash during
|
||||
// the build process and write it to inline-script-checksum.json.
|
||||
// the build process and write it to checksum.js.
|
||||
|
||||
import { testHasLocalStorageOnce } from './src/routes/_utils/testStorage'
|
||||
import { switchToTheme } from './src/routes/_utils/themeEngine'
|
||||
import { basename } from './src/routes/_api/utils'
|
||||
import { onUserIsLoggedOut } from './src/routes/_actions/onUserIsLoggedOut'
|
||||
import { testHasLocalStorageOnce } from '../routes/_utils/testStorage'
|
||||
import { switchToTheme } from '../routes/_utils/themeEngine'
|
||||
import { basename } from '../routes/_api/utils'
|
||||
import { onUserIsLoggedOut } from '../routes/_actions/onUserIsLoggedOut'
|
||||
|
||||
window.__themeColors = process.env.THEME_COLORS
|
||||
|
|
@ -6,7 +6,7 @@ const app = express()
|
|||
const helmet = require('helmet')
|
||||
const uuidv4 = require('uuid/v4')
|
||||
|
||||
const headScriptChecksum = require('../inline-script-checksum').checksum
|
||||
const headScriptChecksum = require('./inline-script/checksum')
|
||||
|
||||
const { PORT = 4002 } = process.env
|
||||
|
||||
|
|
Loading…
Reference in New Issue