Skip to content

Commit adcc534

Browse files
committed
add esbuild fn support
1 parent f58a5d3 commit adcc534

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

.changeset/add-custom-esbuild.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@keystone-6/core": minor
33
---
44

5-
Add support for developers to add `esbuild.keystone.js` to the working directory to replace the default esbuild configuration
5+
Add support for developers to add `esbuild.keystone.js` to the working directory to mutate the default esbuild configuration

packages/core/src/lib/esbuild.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// WARNING: be careful not to import `esbuild` within next
22
import { type BuildOptions } from 'esbuild'
33

4+
function identity (x: BuildOptions) { return x }
5+
46
export function getEsbuildConfig (cwd: string): BuildOptions {
7+
let esbuildFn: typeof identity | undefined
58
try {
6-
return require(require.resolve(`${cwd}/esbuild.keystone.js`))
9+
esbuildFn = require(require.resolve(`${cwd}/esbuild.keystone.js`))
710
} catch (e) {}
11+
esbuildFn ??= identity
812

9-
// default fallback
10-
return {
13+
return esbuildFn({
1114
entryPoints: ['./keystone'],
1215
absWorkingDir: cwd,
1316
bundle: true,
@@ -20,18 +23,15 @@ export function getEsbuildConfig (cwd: string): BuildOptions {
2023
{
2124
name: 'external-node_modules',
2225
setup (build) {
23-
build.onResolve(
24-
{
25-
// don't bundle anything that is NOT a relative import
26-
// WARNING: we can't use a negative lookahead/lookbehind because esbuild uses Go
27-
filter: /(?:^[^.])|(?:^\.[^/.])|(?:^\.\.[^/])/,
28-
},
29-
({ path }) => {
30-
return { external: true, path }
31-
}
32-
)
26+
build.onResolve({
27+
// don't bundle anything that is NOT a relative import
28+
// WARNING: we can't use a negative lookahead/lookbehind because esbuild uses Go
29+
filter: /(?:^[^.])|(?:^\.[^/.])|(?:^\.\.[^/])/,
30+
}, ({ path }) => {
31+
return { external: true, path }
32+
})
3333
},
3434
},
3535
],
36-
}
36+
} satisfies BuildOptions)
3737
}

0 commit comments

Comments
 (0)