// Bundles entry.ts with the scene's ?raw GLSL imports into $OUT/bundle.js plus an index.html. // usage: node bundle.cjs [demo|ridge] (esbuild from NODE_PATH). `demo` bundles the ray-march // standalone page; `ridge` the ridge scene's page (open it with ?probe=1 for the cadence readout). const esbuild = require('esbuild'); const fs = require('fs'); const path = require('path'); const out = process.argv[2]; const demo = process.argv[3] === 'demo'; const ridge = process.argv[3] === 'ridge'; fs.mkdirSync(out, { recursive: true }); const rawPlugin = { name: 'raw', setup(b) { b.onResolve({ filter: /\?raw$/ }, (a) => ({ path: path.resolve(a.resolveDir, a.path.slice(0, -4)), namespace: 'raw', })); b.onLoad({ filter: /.*/, namespace: 'raw' }, (a) => ({ contents: fs.readFileSync(a.path, 'utf8'), loader: 'text', })); }, }; esbuild .build({ entryPoints: [path.join(__dirname, ridge ? 'ridgeDemo.ts' : demo ? 'demo.ts' : 'entry.ts')], bundle: true, outfile: path.join(out, 'bundle.js'), plugins: [rawPlugin], format: 'iife', target: 'es2020', }) .then(() => { if (ridge) { fs.writeFileSync( path.join(out, 'index.html'), 'Ratatoskr ridge scene
' ); return; } fs.writeFileSync( path.join(out, 'index.html'), 'Ratatoskr scene: trace prepass' + (demo ? '
device
' : '') + '' ); });