@@ -4,64 +4,58 @@ import { argv, exit } from "node:process";
44import { readFile } from "node:fs/promises" ;
55
66const replaceBabylonJsImports = {
7- name : "replaceImportMetaDirname" ,
8- setup ( build ) {
9- build . onLoad ( { filter : / .* / } , async ( args ) => {
10- const source = await readFile ( args . path , "utf8" ) ;
7+ name : "replaceImportMetaDirname" ,
8+ setup ( build ) {
9+ build . onLoad ( { filter : / .* / } , async ( args ) => {
10+ const source = await readFile ( args . path , "utf8" ) ;
1111
12- const transformedSource = source
13- . replace ( / " @ b a b y l o n j s \/ c o r e \/ .* " / g, "\"babylonjs\"" )
14- . replace ( / " @ b a b y l o n j s \/ g u i \/ .* " / g, "\"babylonjs-gui\"" ) ;
12+ const transformedSource = source
13+ . replace ( / " @ b a b y l o n j s \/ c o r e \/ .* " / g, '"babylonjs"' )
14+ . replace ( / " @ b a b y l o n j s \/ g u i \/ .* " / g, '"babylonjs-gui"' )
15+ . replace ( / " @ b a b y l o n j s \/ a d d o n s \/ .* " / g, '"babylonjs-addons"' ) ;
1516
16- return {
17- loader : "default" ,
18- contents : transformedSource ,
19- } ;
20- } ) ;
21- } ,
17+ return {
18+ loader : "default" ,
19+ contents : transformedSource ,
20+ } ;
21+ } ) ;
22+ } ,
2223} ;
2324
2425const args = argv . slice ( 2 ) ;
2526const isWatch = args . includes ( "--watch" ) ;
2627
2728const mainBuildOptions = {
28- entryPoints : [
29- "./src/index.ts" ,
30- ] ,
31- bundle : true ,
32- platform : "node" ,
33- target : "node20" , // target version of Node.js
34- format : "cjs" , // output format as CommonJS
35- outfile : "./build/index.node.js" ,
36- treeShaking : false ,
37- loader : {
38- ".ts" : "ts" ,
39- } ,
40- external : [
41- "babylonjs" ,
42- "babylonjs-gui" ,
43- ] ,
44- keepNames : true ,
45- minify : ! isWatch ,
46- plugins : [
47- replaceBabylonJsImports
48- ] ,
29+ entryPoints : [ "./src/index.ts" ] ,
30+ bundle : true ,
31+ platform : "node" ,
32+ target : "node20" , // target version of Node.js
33+ format : "cjs" , // output format as CommonJS
34+ outfile : "./build/index.node.js" ,
35+ treeShaking : false ,
36+ loader : {
37+ ".ts" : "ts" ,
38+ } ,
39+ external : [ "babylonjs" , "babylonjs-gui" ] ,
40+ keepNames : true ,
41+ minify : ! isWatch ,
42+ plugins : [ replaceBabylonJsImports ] ,
4943} ;
5044
5145if ( args . includes ( "--watch" ) ) {
52- esbuild
53- . context ( mainBuildOptions )
54- . then ( async ( buildcontext ) => {
55- await buildcontext . watch ( ) ;
56- console . log ( "Watching..." ) ;
57- } )
58- . catch ( ( error ) => {
59- console . error ( error ) ;
60- exit ( 1 ) ;
61- } ) ;
46+ esbuild
47+ . context ( mainBuildOptions )
48+ . then ( async ( buildcontext ) => {
49+ await buildcontext . watch ( ) ;
50+ console . log ( "Watching..." ) ;
51+ } )
52+ . catch ( ( error ) => {
53+ console . error ( error ) ;
54+ exit ( 1 ) ;
55+ } ) ;
6256} else {
63- esbuild . build ( mainBuildOptions ) . catch ( ( error ) => {
64- console . error ( error ) ;
65- exit ( 1 ) ;
66- } ) ;
57+ esbuild . build ( mainBuildOptions ) . catch ( ( error ) => {
58+ console . error ( error ) ;
59+ exit ( 1 ) ;
60+ } ) ;
6761}
0 commit comments