@@ -4,7 +4,7 @@ import fastifyStatic from "@fastify/static";
44import fastifyFormbody from "@fastify/formbody" ;
55
66import { Liquid } from "liquidjs" ;
7- import webpack from "webpack " ;
7+ import esbuild from "esbuild " ;
88import { JSONFilePreset } from "lowdb/node" ;
99
1010import fs from "node:fs" ;
@@ -25,7 +25,7 @@ const db = await JSONFilePreset(path.join(__dirname, "data", "data.json"), {
2525 consume : [ ] ,
2626} ) ;
2727
28- function buildClientsideAssets ( ) {
28+ async function buildClientsideAssets ( ) {
2929 if ( ! fs . existsSync ( publicPath ) ) {
3030 fs . mkdirSync ( publicPath ) ;
3131 }
@@ -34,28 +34,25 @@ function buildClientsideAssets() {
3434 "npx tailwindcss -i ./statics/css/style.css -o ./public/css/style.css"
3535 ) ;
3636
37- // build js bundle with webpack
38- const compiler = webpack ( {
39- entry : path . join ( staticsPath , "js" , "main.js" ) ,
40- mode : "production" ,
41- output : {
42- path : path . join ( publicPath , "js" ) ,
43- filename : "main.js" ,
44- } ,
45- resolve : {
46- alias : {
47- fs : false ,
48- path : false ,
49- } ,
50- modules : [ path . join ( staticsPath , "js" ) , "node_modules" ] ,
51- } ,
52- } ) ;
53- compiler . run ( ) ;
37+ // build js bundle with esbuild
38+ await esbuild
39+ . build ( {
40+ entryPoints : [ path . join ( staticsPath , "js" , "main.js" ) ] ,
41+ bundle : true ,
42+ minify : true , // equivalent to webpack production mode
43+ outfile : path . join ( publicPath , "js" , "main.js" ) ,
44+ platform : "browser" ,
45+ external : [ "fs" , "path" ] ,
46+ } )
47+ . catch ( ( error ) => {
48+ console . error ( `Failed to build JS bundle. Error: ${ error } ` ) ;
49+ process . exit ( 1 ) ;
50+ } ) ;
5451}
5552
5653const routePrefix = process . env . WEEKNOTES_ROUTE_PREFIX ?? "" ;
5754
58- buildClientsideAssets ( ) ;
55+ await buildClientsideAssets ( ) ;
5956
6057function getRoutePath ( path = "" ) {
6158 const basePath = routePrefix ? `/${ routePrefix } ` : "/" ;
0 commit comments