Skip to content

Commit 9d10117

Browse files
committed
fix: skip esbuild bundling during toJSON() article discovery
The esbuild plugin's eleventy.before hook runs during toJSON() calls, but bundling is unnecessary for article discovery and requires env vars that aren't available in every CI step. Skip bundling when outputMode is "json".
1 parent 6210dd5 commit 9d10117

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

11ty/esbuild.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ export default async function (eleventyConfig: UserConfig): Promise<void> {
99

1010
let hashes: Record<string, string> | undefined
1111

12-
eleventyConfig.on('eleventy.before', async function () {
13-
hashes = await bundle(await globby(['www/**/index.ts', 'www/**/worker.ts']))
14-
})
12+
eleventyConfig.on(
13+
'eleventy.before',
14+
async function ({ outputMode }: { outputMode: string }) {
15+
if (outputMode === 'json') return
16+
hashes = await bundle(await globby(['www/**/index.ts', 'www/**/worker.ts']))
17+
}
18+
)
1519

1620
eleventyConfig.addTransform('esbuild-translate-hashes', function (content) {
1721
return translateHashes(this.page.inputPath, this.page.url, hashes, content) ?? content

types/eleventy.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ declare module '@11ty/eleventy' {
3333

3434
interface UserConfig {
3535
addWatchTarget(path: string): void
36-
on(event: string, callback: () => void | Promise<void>): void
36+
on(event: string, callback: (...args: any[]) => void | Promise<void>): void
3737
addTransform(
3838
name: string,
3939
callback: (

0 commit comments

Comments
 (0)