2
2
// 1. Bundle as single file
3
3
// 2. Perform dynamic import for page files (code splitting)
4
4
5
- import { join } from "jsr:@std/path/join" ;
5
+ import {
6
+ basename ,
7
+ bold ,
8
+ commonjsPlugin ,
9
+ delay ,
10
+ denoPlugins ,
11
+ dim ,
12
+ esbuild ,
13
+ exists ,
14
+ extname ,
15
+ join ,
16
+ loadConfig ,
17
+ parseArgs ,
18
+ relative ,
19
+ walk ,
20
+ } from "../deps.ts" ;
6
21
import { Logger } from "../lib/logger.ts" ;
7
22
import { Runner } from "../lib/runner.ts" ;
8
- import { bold , dim } from "jsr:@std/fmt/colors" ;
9
- import { relative } from "jsr:@std/path/relative" ;
10
- import { exists } from "jsr:@std/fs/exists" ;
11
- import { walk } from "jsr:@std/fs/walk" ;
12
- import { basename , extname } from "jsr:@std/path" ;
13
- import { loadConfig } from "npm:c12" ;
14
23
import { defaultConfig } from "../lib/config.ts" ;
15
24
import renderEjs from "../scripts/render_ejs.js" ;
16
25
import { buildRouter } from "../lib/router.ts" ;
17
26
import deno from "../../deno.json" with { type : "json" } ;
18
- import { delay } from "jsr:@std/async/delay" ;
19
-
20
- // @deno -types="https://deno.land/x/esbuild/mod.d.ts"
21
- import * as esbuild from "https://deno.land/x/esbuild/mod.js" ;
22
- import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@^0.10.3" ;
23
- import commonjsPlugin from "npm:@chialab/esbuild-plugin-commonjs" ;
24
27
25
28
import "../lib/meta/prod.js" ;
26
- import { parseArgs } from "jsr:@std/cli@^0.224.7/parse-args" ;
27
29
28
30
const logger = new Logger ( ) ;
29
31
const runner = new Runner ( logger ) ;
30
32
console . log ( bold ( "Building the Production Server" ) ) ;
31
33
const args = parseArgs ( Deno . args , {
32
34
boolean : [ "single" ] ,
33
- default : { single : true }
34
- } )
35
+ default : { single : true } ,
36
+ } ) ;
35
37
36
38
// set constants
37
39
logger . info ( "Setting up" ) ;
107
109
}
108
110
}
109
111
110
-
111
-
112
112
// await runner.run(Deno.execPath(), ["run", "-A", "./internal/scripts/render_ejs.js"]);
113
113
const ejsMap = await renderEjs ( false ) ;
114
114
logger . fine ( "EJS Rendered!" ) ;
@@ -174,7 +174,7 @@ await Deno.mkdir(outClientDir, { recursive: true });
174
174
175
175
if ( args . single ) {
176
176
// skip
177
- logger . info ( "Single Build -- Pages Not Rendered Separately " )
177
+ logger . info ( "Single Build -- Pages Not Rendered Separately " ) ;
178
178
} else {
179
179
await esbuild . build ( {
180
180
entryPoints : Array . from ( routerMap . entries ( ) ) . map ( ( e ) => e [ 1 ] . fullPath ) ,
@@ -183,9 +183,12 @@ if (args.single) {
183
183
format : "esm" ,
184
184
jsx : "automatic" ,
185
185
jsxImportSource : deno . compilerOptions . jsxImportSource ,
186
- plugins : [ ...denoPlugins ( {
187
- configPath : join ( cwd , "deno.json" ) ,
188
- } ) , commonjsPlugin ( ) ] ,
186
+ plugins : [
187
+ ...denoPlugins ( {
188
+ configPath : join ( cwd , "deno.json" ) ,
189
+ } ) ,
190
+ commonjsPlugin ( ) ,
191
+ ] ,
189
192
} ) ;
190
193
191
194
for ( const [ k , v ] of Array . from ( routerMap . entries ( ) ) ) {
@@ -200,7 +203,10 @@ if (args.single) {
200
203
join ( outDir , "client/blog/[name]/index.server.js" ) ,
201
204
Deno . readTextFileSync (
202
205
join ( outDir , "client/blog/[name]/index.server.js" ) ,
203
- ) . replaceAll ( 'from "url"' , 'from "node:url"' ) . replaceAll ( 'from "fs"' , 'from "node:fs"' ) . replaceAll ( 'from "path"' , 'from "node:path"' )
206
+ ) . replaceAll ( 'from "url"' , 'from "node:url"' ) . replaceAll (
207
+ 'from "fs"' ,
208
+ 'from "node:fs"' ,
209
+ ) . replaceAll ( 'from "path"' , 'from "node:path"' ) ,
204
210
) ;
205
211
206
212
logger . fine ( "Bundled Pages!" ) ;
@@ -276,8 +282,16 @@ for await (
276
282
}
277
283
278
284
// bundling svgs
279
- logger . info ( "Using SVGO to optimize SVGs" )
280
- await runner . run ( Deno . execPath ( ) , [ "run" , "-A" , "npm:svgo" , "-f" , join ( cwd , "assets" , "svg" ) , "-o" , join ( outDir , "assets" , "svg" ) ] )
285
+ logger . info ( "Using SVGO to optimize SVGs" ) ;
286
+ await runner . run ( Deno . execPath ( ) , [
287
+ "run" ,
288
+ "-A" ,
289
+ "npm:svgo" ,
290
+ "-f" ,
291
+ join ( cwd , "assets" , "svg" ) ,
292
+ "-o" ,
293
+ join ( outDir , "assets" , "svg" ) ,
294
+ ] ) ;
281
295
282
296
// bundling content
283
297
logger . info ( "Bundling Content" ) ;
@@ -332,14 +346,14 @@ Deno.writeTextFileSync(
332
346
) . replaceAll ( 'from "url"' , 'from "node:url"' ) ,
333
347
) ;
334
348
335
- logger . info ( "Minifying Server" )
349
+ logger . info ( "Minifying Server" ) ;
336
350
await esbuild . build ( {
337
351
entryPoints : [ join ( outDir , "server.js" ) ] ,
338
352
outfile : join ( outDir , "server.min.js" ) ,
339
353
minify : true ,
340
354
plugins : [ ...denoPlugins ( {
341
355
configPath : join ( cwd , "deno.json" ) ,
342
- } ) ]
356
+ } ) ] ,
343
357
} ) ;
344
358
345
359
logger . fine ( `Server built at ${ join ( outDir , "server.js" ) } ` ) ;
0 commit comments