File tree 2 files changed +33
-13
lines changed
packages/open-next/src/build
2 files changed +33
-13
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { buildSync } from "esbuild";
6
6
import type { OpenNextConfig } from "types/open-next.js" ;
7
7
8
8
import logger from "../logger.js" ;
9
- import { DEV_CONFIG } from "./constant .js" ;
9
+ import { buildDevConfig } from "./helper .js" ;
10
10
import { validateConfig } from "./validateConfig.js" ;
11
11
12
12
/**
@@ -77,25 +77,19 @@ export function compileOpenNextConfigNode(
77
77
const outputPath = path . join ( outputDir , "open-next.config.mjs" ) ;
78
78
logger . debug ( "Compiling open-next.config.ts for Node." , outputPath ) ;
79
79
80
+ if ( dev ) {
81
+ buildDevConfig ( outputPath , externals ) ;
82
+ return outputPath ;
83
+ }
84
+
80
85
//Check if open-next.config.ts exists
81
86
if ( ! fs . existsSync ( sourcePath ) ) {
82
87
//Create a simple open-next.config.mjs file
83
88
logger . debug ( "Cannot find open-next.config.ts. Using default config." ) ;
84
89
fs . writeFileSync ( outputPath , "export default { default: { } };" ) ;
85
90
} else {
86
91
buildSync ( {
87
- ...( dev
88
- ? {
89
- stdin : {
90
- contents : DEV_CONFIG ,
91
- resolveDir : process . cwd ( ) ,
92
- loader : "ts" ,
93
- sourcefile : "open-next.config.ts" ,
94
- } ,
95
- }
96
- : {
97
- entryPoints : [ sourcePath ] ,
98
- } ) ,
92
+ entryPoints : [ sourcePath ] ,
99
93
outfile : outputPath ,
100
94
bundle : true ,
101
95
format : "esm" ,
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import type {
11
11
} from "types/open-next.js" ;
12
12
13
13
import logger from "../logger.js" ;
14
+ import { DEV_CONFIG } from "./constant.js" ;
14
15
15
16
const require = createRequire ( import . meta. url ) ;
16
17
const __dirname = url . fileURLToPath ( new URL ( "." , import . meta. url ) ) ;
@@ -440,3 +441,28 @@ export async function isEdgeRuntime(
440
441
export function getPackagePath ( options : BuildOptions ) {
441
442
return path . relative ( options . monorepoRoot , options . appBuildOutputPath ) ;
442
443
}
444
+
445
+ export function buildDevConfig ( outputPath : string , externals : string [ ] ) {
446
+ buildSync ( {
447
+ stdin : {
448
+ contents : DEV_CONFIG ,
449
+ resolveDir : process . cwd ( ) ,
450
+ loader : "ts" ,
451
+ sourcefile : "open-next.config.ts" ,
452
+ } ,
453
+ outfile : outputPath ,
454
+ bundle : true ,
455
+ format : "esm" ,
456
+ target : [ "node18" ] ,
457
+ external : externals ,
458
+ platform : "node" ,
459
+ banner : {
460
+ js : [
461
+ "import { createRequire as topLevelCreateRequire } from 'module';" ,
462
+ "const require = topLevelCreateRequire(import.meta.url);" ,
463
+ "import bannerUrl from 'url';" ,
464
+ "const __dirname = bannerUrl.fileURLToPath(new URL('.', import.meta.url));" ,
465
+ ] . join ( "" ) ,
466
+ } ,
467
+ } ) ;
468
+ }
You can’t perform that action at this time.
0 commit comments