Skip to content

Commit 901fec2

Browse files
committed
add support for developers to replace the default esbuild configuration
1 parent fe7e468 commit 901fec2

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

packages/core/src/lib/esbuild.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
// WARNING: be careful not to import `esbuild` within next
2-
import type { BuildOptions } from 'esbuild'
2+
import { type BuildOptions } from 'esbuild'
33

44
export function getEsbuildConfig (cwd: string): BuildOptions {
5+
try {
6+
return require(require.resolve(`${cwd}/esbuild.keystone.js`))
7+
} catch (e) {}
8+
9+
// default fallback
510
return {
611
entryPoints: ['./keystone'],
712
absWorkingDir: cwd,
@@ -17,16 +22,12 @@ export function getEsbuildConfig (cwd: string): BuildOptions {
1722
setup (build) {
1823
build.onResolve(
1924
{
20-
// this regex is intended to be the opposite of /^\.\.?(?:\/|$)/
21-
// so it matches anything that isn't a relative import
22-
// so this means that we're only going to bundle relative imports
23-
// we can't use a negative lookahead/lookbehind because this regex is executed
24-
// by Go's regex package which doesn't support them
25-
// this regex could have less duplication with nested groups but this is probably easier to read
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
2627
filter: /(?:^[^.])|(?:^\.[^/.])|(?:^\.\.[^/])/,
2728
},
28-
args => {
29-
return { external: true, path: args.path }
29+
({ path }) => {
30+
return { external: true, path }
3031
}
3132
)
3233
},

0 commit comments

Comments
 (0)