Skip to content

Commit 4b2fc0b

Browse files
committed
update to new esbuild context api
1 parent cc470e7 commit 4b2fc0b

File tree

3 files changed

+72
-57
lines changed

3 files changed

+72
-57
lines changed

packages/core/build.js

+24-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ const config = {
99
minify: true,
1010
sourcemap: true,
1111
target: 'es2020',
12-
plugins: [nodeExternalsPlugin()],
12+
plugins: [
13+
nodeExternalsPlugin(),
14+
{
15+
name: 'inertia',
16+
setup(build) {
17+
let count = 0
18+
build.onEnd((result) => {
19+
if (count++ !== 0) {
20+
console.log(`Rebuilding ${build.initialOptions.entryPoints} (${build.initialOptions.format})…`)
21+
}
22+
})
23+
},
24+
},
25+
],
1326
}
1427

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

22-
builds.forEach((build) => {
23-
esbuild
24-
.build({ ...config, ...build, ...watcher(build) })
25-
.then(() => console.log(`${watch ? 'Watching' : 'Built'} ${build.entryPoints} (${build.format})…`))
26-
.catch(() => process.exit(1))
27-
})
35+
builds.forEach(async (build) => {
36+
const context = await esbuild.context({ ...config, ...build })
2837

29-
function watcher(build) {
30-
return watch
31-
? {
32-
watch: {
33-
onRebuild: (error) =>
34-
error
35-
? console.error('Watch failed:', error)
36-
: console.log(`Rebuilding ${build.entryPoints} (${build.format})…`),
37-
},
38-
}
39-
: {}
40-
}
38+
if (watch) {
39+
console.log(`Watching ${build.entryPoints} (${build.format})…`)
40+
await context.watch()
41+
} else {
42+
console.log(`Built ${build.entryPoints} (${build.format})…`)
43+
context.dispose()
44+
}
45+
})

packages/react/build.js

+24-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ const config = {
99
minify: true,
1010
sourcemap: true,
1111
target: 'es2020',
12-
plugins: [nodeExternalsPlugin()],
12+
plugins: [
13+
nodeExternalsPlugin(),
14+
{
15+
name: 'inertia',
16+
setup(build) {
17+
let count = 0
18+
build.onEnd((result) => {
19+
if (count++ !== 0) {
20+
console.log(`Rebuilding ${build.initialOptions.entryPoints} (${build.initialOptions.format})…`)
21+
}
22+
})
23+
},
24+
},
25+
],
1326
}
1427

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

22-
builds.forEach((build) => {
23-
esbuild
24-
.build({ ...config, ...build, ...watcher(build) })
25-
.then(() => console.log(`${watch ? 'Watching' : 'Built'} ${build.entryPoints} (${build.format})…`))
26-
.catch(() => process.exit(1))
27-
})
35+
builds.forEach(async (build) => {
36+
const context = await esbuild.context({ ...config, ...build })
2837

29-
function watcher(build) {
30-
return watch
31-
? {
32-
watch: {
33-
onRebuild: (error) =>
34-
error
35-
? console.error('Watch failed:', error)
36-
: console.log(`Rebuilding ${build.entryPoints} (${build.format})…`),
37-
},
38-
}
39-
: {}
40-
}
38+
if (watch) {
39+
console.log(`Watching ${build.entryPoints} (${build.format})…`)
40+
await context.watch()
41+
} else {
42+
console.log(`Built ${build.entryPoints} (${build.format})…`)
43+
context.dispose()
44+
}
45+
})

packages/vue3/build.js

+24-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ const config = {
99
minify: true,
1010
sourcemap: true,
1111
target: 'es2020',
12-
plugins: [nodeExternalsPlugin()],
12+
plugins: [
13+
nodeExternalsPlugin(),
14+
{
15+
name: 'inertia',
16+
setup(build) {
17+
let count = 0
18+
build.onEnd((result) => {
19+
if (count++ !== 0) {
20+
console.log(`Rebuilding ${build.initialOptions.entryPoints} (${build.initialOptions.format})…`)
21+
}
22+
})
23+
},
24+
},
25+
],
1326
}
1427

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

22-
builds.forEach((build) => {
23-
esbuild
24-
.build({ ...config, ...build, ...watcher(build) })
25-
.then(() => console.log(`${watch ? 'Watching' : 'Built'} ${build.entryPoints} (${build.format})…`))
26-
.catch(() => process.exit(1))
27-
})
35+
builds.forEach(async (build) => {
36+
const context = await esbuild.context({ ...config, ...build })
2837

29-
function watcher(build) {
30-
return watch
31-
? {
32-
watch: {
33-
onRebuild: (error) =>
34-
error
35-
? console.error('Watch failed:', error)
36-
: console.log(`Rebuilding ${build.entryPoints} (${build.format})…`),
37-
},
38-
}
39-
: {}
40-
}
38+
if (watch) {
39+
console.log(`Watching ${build.entryPoints} (${build.format})…`)
40+
await context.watch()
41+
} else {
42+
console.log(`Built ${build.entryPoints} (${build.format})…`)
43+
context.dispose()
44+
}
45+
})

0 commit comments

Comments
 (0)