Skip to content

Commit

Permalink
update to new esbuild context api
Browse files Browse the repository at this point in the history
  • Loading branch information
joetannenbaum committed Mar 7, 2025
1 parent cc470e7 commit 4b2fc0b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 57 deletions.
43 changes: 24 additions & 19 deletions packages/core/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,20 @@ const config = {
minify: true,
sourcemap: true,
target: 'es2020',
plugins: [nodeExternalsPlugin()],
plugins: [
nodeExternalsPlugin(),
{
name: 'inertia',
setup(build) {
let count = 0
build.onEnd((result) => {
if (count++ !== 0) {
console.log(`Rebuilding ${build.initialOptions.entryPoints} (${build.initialOptions.format})…`)
}
})
},
},
],
}

const builds = [
Expand All @@ -19,22 +32,14 @@ const builds = [
{ entryPoints: ['src/server.ts'], format: 'cjs', outfile: 'dist/server.js', platform: 'node' },
]

builds.forEach((build) => {
esbuild
.build({ ...config, ...build, ...watcher(build) })
.then(() => console.log(`${watch ? 'Watching' : 'Built'} ${build.entryPoints} (${build.format})…`))
.catch(() => process.exit(1))
})
builds.forEach(async (build) => {
const context = await esbuild.context({ ...config, ...build })

function watcher(build) {
return watch
? {
watch: {
onRebuild: (error) =>
error
? console.error('Watch failed:', error)
: console.log(`Rebuilding ${build.entryPoints} (${build.format})…`),
},
}
: {}
}
if (watch) {
console.log(`Watching ${build.entryPoints} (${build.format})…`)
await context.watch()
} else {
console.log(`Built ${build.entryPoints} (${build.format})…`)
context.dispose()
}
})
43 changes: 24 additions & 19 deletions packages/react/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,20 @@ const config = {
minify: true,
sourcemap: true,
target: 'es2020',
plugins: [nodeExternalsPlugin()],
plugins: [
nodeExternalsPlugin(),
{
name: 'inertia',
setup(build) {
let count = 0
build.onEnd((result) => {
if (count++ !== 0) {
console.log(`Rebuilding ${build.initialOptions.entryPoints} (${build.initialOptions.format})…`)
}
})
},
},
],
}

const builds = [
Expand All @@ -19,22 +32,14 @@ const builds = [
{ entryPoints: ['src/server.ts'], format: 'cjs', outfile: 'dist/server.js', platform: 'node' },
]

builds.forEach((build) => {
esbuild
.build({ ...config, ...build, ...watcher(build) })
.then(() => console.log(`${watch ? 'Watching' : 'Built'} ${build.entryPoints} (${build.format})…`))
.catch(() => process.exit(1))
})
builds.forEach(async (build) => {
const context = await esbuild.context({ ...config, ...build })

function watcher(build) {
return watch
? {
watch: {
onRebuild: (error) =>
error
? console.error('Watch failed:', error)
: console.log(`Rebuilding ${build.entryPoints} (${build.format})…`),
},
}
: {}
}
if (watch) {
console.log(`Watching ${build.entryPoints} (${build.format})…`)
await context.watch()
} else {
console.log(`Built ${build.entryPoints} (${build.format})…`)
context.dispose()
}
})
43 changes: 24 additions & 19 deletions packages/vue3/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,20 @@ const config = {
minify: true,
sourcemap: true,
target: 'es2020',
plugins: [nodeExternalsPlugin()],
plugins: [
nodeExternalsPlugin(),
{
name: 'inertia',
setup(build) {
let count = 0
build.onEnd((result) => {
if (count++ !== 0) {
console.log(`Rebuilding ${build.initialOptions.entryPoints} (${build.initialOptions.format})…`)
}
})
},
},
],
}

const builds = [
Expand All @@ -19,22 +32,14 @@ const builds = [
{ entryPoints: ['src/server.ts'], format: 'cjs', outfile: 'dist/server.js', platform: 'node' },
]

builds.forEach((build) => {
esbuild
.build({ ...config, ...build, ...watcher(build) })
.then(() => console.log(`${watch ? 'Watching' : 'Built'} ${build.entryPoints} (${build.format})…`))
.catch(() => process.exit(1))
})
builds.forEach(async (build) => {
const context = await esbuild.context({ ...config, ...build })

function watcher(build) {
return watch
? {
watch: {
onRebuild: (error) =>
error
? console.error('Watch failed:', error)
: console.log(`Rebuilding ${build.entryPoints} (${build.format})…`),
},
}
: {}
}
if (watch) {
console.log(`Watching ${build.entryPoints} (${build.format})…`)
await context.watch()
} else {
console.log(`Built ${build.entryPoints} (${build.format})…`)
context.dispose()
}
})

0 comments on commit 4b2fc0b

Please sign in to comment.