11import { createRequire } from "module" ;
22import { glsl } from "esbuild-plugin-glsl" ;
3- import tsPaths from "esbuild-ts-paths" ;
43import glob from "tiny-glob" ;
54import esbuild from "esbuild" ;
65
76const require = createRequire ( import . meta. url ) ;
87const pkg = require ( "./package" ) ;
98
109const minify = process . argv . includes ( "-m" ) ;
11- const watch = process . argv . includes ( "-w" ) ;
12- const plugins = [ glsl ( { minify } ) , tsPaths ( ) ] ;
10+ const plugins = [ glsl ( { minify } ) ] ;
1311const external = [ "three" , "spatial-controls" , "tweakpane" ] ;
1412
1513const date = new Date ( ) ;
@@ -20,42 +18,29 @@ const banner = `/**
2018 * @license ${ pkg . license }
2119 */` ;
2220
23- await esbuild . build ( {
21+ const workers = {
2422 entryPoints : await glob ( "src/**/worker.js" ) ,
2523 outExtension : { ".js" : ".txt" } ,
2624 outdir : "tmp" ,
2725 target : "es6" ,
2826 logLevel : "info" ,
2927 format : "iife" ,
3028 bundle : true ,
31- minify,
32- watch
33- } ) . catch ( ( ) => process . exit ( 1 ) ) ;
29+ minify
30+ } ;
3431
35- await esbuild . build ( {
32+ const demo = {
3633 entryPoints : [ "demo/src/index.js" ] ,
3734 outdir : "public/demo" ,
3835 target : "es6" ,
3936 logLevel : "info" ,
4037 format : "iife" ,
4138 bundle : true ,
4239 plugins,
43- minify,
44- watch
45- } ) . catch ( ( ) => process . exit ( 1 ) ) ;
46-
47- await esbuild . build ( {
48- entryPoints : [ "manual/assets/js/libs/vendor.js" ] ,
49- outdir : "manual/assets/js/dist/libs" ,
50- globalName : "VENDOR" ,
51- target : "es6" ,
52- logLevel : "info" ,
53- format : "iife" ,
54- bundle : true ,
5540 minify
56- } ) . catch ( ( ) => process . exit ( 1 ) ) ;
41+ } ;
5742
58- await esbuild . build ( {
43+ const manual = {
5944 entryPoints : [ "manual/assets/js/src/index.js" ]
6045 . concat ( await glob ( "manual/assets/js/src/demos/*.js" ) ) ,
6146 outdir : "manual/assets/js/dist" ,
@@ -65,9 +50,36 @@ await esbuild.build({
6550 bundle : true ,
6651 external,
6752 plugins,
68- minify,
69- watch
70- } ) . catch ( ( ) => process . exit ( 1 ) ) ;
53+ minify
54+ } ;
55+
56+ await esbuild . build ( {
57+ entryPoints : [ "manual/assets/js/libs/vendor.js" ] ,
58+ outdir : "manual/assets/js/dist/libs" ,
59+ globalName : "VENDOR" ,
60+ target : "es6" ,
61+ logLevel : "info" ,
62+ format : "iife" ,
63+ bundle : true ,
64+ minify
65+ } ) ;
66+
67+ if ( process . argv . includes ( "-w" ) ) {
68+
69+ const ctxWorkers = await esbuild . context ( workers ) ;
70+ const ctxDemo = await esbuild . context ( demo ) ;
71+ const ctxManual = await esbuild . context ( manual ) ;
72+ await ctxWorkers . watch ( ) ;
73+ await ctxDemo . watch ( ) ;
74+ await ctxManual . watch ( ) ;
75+
76+ } else {
77+
78+ await esbuild . build ( workers ) ;
79+ await esbuild . build ( demo ) ;
80+ await esbuild . build ( manual ) ;
81+
82+ }
7183
7284await esbuild . build ( {
7385 entryPoints : [ "src/index.js" ] ,
@@ -79,7 +91,7 @@ await esbuild.build({
7991 bundle : true ,
8092 external,
8193 plugins
82- } ) . catch ( ( ) => process . exit ( 1 ) ) ;
94+ } ) ;
8395
8496await esbuild . build ( {
8597 entryPoints : [ "src/index.js" ] ,
@@ -91,11 +103,11 @@ await esbuild.build({
91103 bundle : true ,
92104 external,
93105 plugins
94- } ) . catch ( ( ) => process . exit ( 1 ) ) ;
106+ } ) ;
95107
96108// @todo Remove in next major release.
97109const globalName = pkg . name . replace ( / - / g, "" ) . toUpperCase ( ) ;
98- const requireShim = ` if(typeof window==="object"&&!window.require)window.require=()=>window.THREE;` ;
110+ const requireShim = " if(typeof window===\ "object\ "&&!window.require)window.require=()=>window.THREE;" ;
99111const footer = `if(typeof module==="object"&&module.exports)module.exports=${ globalName } ;` ;
100112
101113await esbuild . build ( {
@@ -110,7 +122,7 @@ await esbuild.build({
110122 globalName,
111123 external,
112124 plugins
113- } ) . catch ( ( ) => process . exit ( 1 ) ) ;
125+ } ) ;
114126
115127await esbuild . build ( {
116128 entryPoints : [ "src/index.js" ] ,
@@ -125,4 +137,4 @@ await esbuild.build({
125137 external,
126138 plugins,
127139 minify
128- } ) . catch ( ( ) => process . exit ( 1 ) ) ;
140+ } ) ;
0 commit comments