improve esbuild config: report reload time into console!
This commit is contained in:
parent
099c0ebaf0
commit
eaa48d7860
2 changed files with 6 additions and 16 deletions
|
|
@ -3,7 +3,6 @@ import * as esbuild from 'esbuild'
|
|||
import fs from 'fs'
|
||||
// import htmlPlugin from '@chialab/esbuild-plugin-html'
|
||||
import server from './server.js'
|
||||
import { analyzeMetafile } from 'esbuild'
|
||||
import { clients, plugins } from './scripts/esbuildPlugins.mjs'
|
||||
import { generateSW } from 'workbox-build'
|
||||
import { getSwAdditionalEntries } from './scripts/build.js'
|
||||
|
|
@ -40,8 +39,10 @@ const prod = process.argv.includes('--prod')
|
|||
|
||||
const banner = [
|
||||
'window.global = globalThis;',
|
||||
// report reload time
|
||||
dev && 'if (sessionStorage.lastReload) { const [rebuild, reloadStart] = sessionStorage.lastReload.split(","); const now = Date.now(); console.log(`rebuild + reload:`, rebuild, "+", now - reloadStart, "=", ((rebuild + (now - reloadStart)) / 1000).toFixed(1) + "s");sessionStorage.lastReload = ""; }',
|
||||
// auto-reload
|
||||
dev && '(() => new EventSource("/esbuild").onmessage = ({ data: _data }) => {const data = JSON.parse(_data);if (!data.update)return;sessionStorage.lastReload = JSON.stringify({buildTime:data.update.time, reloadStart:Date.now()});location.reload()})();'
|
||||
dev && ';(() => new EventSource("/esbuild").onmessage = ({ data: _data }) => { if (!_data) return; const data = JSON.parse(_data); if (!data.update) return; sessionStorage.lastReload = `${data.update.time},${Date.now()}`; location.reload() })();'
|
||||
].filter(Boolean)
|
||||
|
||||
const buildingVersion = new Date().toISOString().split(':')[0]
|
||||
|
|
@ -115,7 +116,7 @@ if (dev) {
|
|||
})
|
||||
} else {
|
||||
const result = await ctx.rebuild()
|
||||
// console.log(await analyzeMetafile(result.metafile))
|
||||
// console.log(await esbuild.analyzeMetafile(result.metafile))
|
||||
|
||||
if (prod) {
|
||||
fs.writeFileSync('dist/version.txt', buildingVersion, 'utf-8')
|
||||
|
|
|
|||
|
|
@ -120,17 +120,6 @@ export const gameAdditionalState = proxy({
|
|||
|
||||
window.gameAdditionalState = gameAdditionalState
|
||||
|
||||
// todo thats weird workaround, probably we can do better?
|
||||
let forceDisableLeaveWarning = false
|
||||
const info = console.info
|
||||
console.info = (...args) => {
|
||||
const message = args[0]
|
||||
if (message === '[webpack-dev-server] App updated. Recompiling...') {
|
||||
forceDisableLeaveWarning = true
|
||||
}
|
||||
info.apply(console, args)
|
||||
}
|
||||
|
||||
const savePlayers = () => {
|
||||
if (!window.singlePlayerServer) return
|
||||
for (const player of window.singlePlayerServer.players) {
|
||||
|
|
@ -151,7 +140,7 @@ window.addEventListener('unload', (e) => {
|
|||
window.addEventListener('beforeunload', (event) => {
|
||||
// todo-low maybe exclude chat?
|
||||
if (!isGameActive(true) && activeModalStack.at(-1)?.elem.id !== 'chat') return
|
||||
if (forceDisableLeaveWarning && options.preventDevReloadWhilePlaying === false) return
|
||||
if (sessionStorage.lastReload && options.preventDevReloadWhilePlaying === false) return
|
||||
|
||||
// For major browsers doning only this is enough
|
||||
event.preventDefault()
|
||||
|
|
@ -159,6 +148,6 @@ window.addEventListener('beforeunload', (event) => {
|
|||
// Display a confirmation prompt
|
||||
event.returnValue = '' // Required for some browsers
|
||||
return 'The game is running. Are you sure you want to close this page?'
|
||||
});
|
||||
})
|
||||
|
||||
window.miscUiState = miscUiState
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue