Skip to content

Commit

Permalink
Don't eagerly load all JS assets (#3929)
Browse files Browse the repository at this point in the history
Co-authored-by: Hailey <[email protected]>
  • Loading branch information
mary-ext and haileyok authored Sep 2, 2024
1 parent 1225e84 commit 05ac76f
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions scripts/post-web-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@ const path = require('path')
const fs = require('fs')

const projectRoot = path.join(__dirname, '..')
const webBuildJs = path.join(projectRoot, 'web-build', 'static', 'js')
const templateFile = path.join(
projectRoot,
'bskyweb',
'templates',
'scripts.html',
)

const jsFiles = fs.readdirSync(webBuildJs).filter(name => name.endsWith('.js'))
jsFiles.sort((a, b) => {
// make sure main is written last
if (a.startsWith('main')) return 1
if (b.startsWith('main')) return -1
return a.localeCompare(b)
})
const {entrypoints} = require(path.join(
projectRoot,
'web-build/asset-manifest.json',
))

console.log(`Found ${jsFiles.length} js files in web-build`)
console.log(`Found ${entrypoints.length} entrypoints`)
console.log(`Writing ${templateFile}`)

const outputFile = jsFiles
.map(name => `<script defer="defer" src="/static/js/${name}"></script>`)
const outputFile = entrypoints
.map(name => {
const file = path.basename(name)
return `<script defer="defer" src="/static/js/${file}"></script>`
})
.join('\n')
fs.writeFileSync(templateFile, outputFile)

0 comments on commit 05ac76f

Please sign in to comment.