Skip to content

Commit

Permalink
display output size on build
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Oct 7, 2023
1 parent 7ad7ef2 commit b68ef15
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import server from './server.js'
import { clients, plugins } from './scripts/esbuildPlugins.mjs'
import { generateSW } from 'workbox-build'
import { getSwAdditionalEntries } from './scripts/build.js'
import { build } from 'esbuild'

//@ts-ignore
try { await import('./localSettings.mjs') } catch { }
Expand All @@ -26,7 +27,8 @@ const banner = [

const buildingVersion = new Date().toISOString().split(':')[0]

const ctx = await esbuild.context({
/** @type {import('esbuild').BuildOptions} */
const buildOptions = {
bundle: true,
entryPoints: ['src/index.ts'],
target: ['es2020'],
Expand Down Expand Up @@ -77,9 +79,10 @@ const ctx = await esbuild.context({
write: false,
// todo would be better to enable?
// preserveSymlinks: true,
})
}

if (watch) {
const ctx = await esbuild.context(buildOptions)
await ctx.watch()
server.app.get('/esbuild', (req, res, next) => {
res.writeHead(200, {
Expand All @@ -103,7 +106,7 @@ if (watch) {
})
})
} else {
const result = await ctx.rebuild()
const result = await build(buildOptions)
// console.log(await esbuild.analyzeMetafile(result.metafile))

if (prod) {
Expand All @@ -119,6 +122,4 @@ if (watch) {
swDest: 'dist/service-worker.js',
})
}

await ctx.dispose()
}

0 comments on commit b68ef15

Please sign in to comment.