Download build.mjs from mmrech/ASCEND: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/mmrech/ASCEND/resolve/main/build.mjs
- Command line
-
hf download hf://spaces/mmrech/ASCEND/build.mjs
-
curl -L -o build.mjs https://huggingface.co/spaces/mmrech/ASCEND/resolve/main/build.mjs
1.19 kB
| /** Build the standalone index.html from source.html + style.css + data.json + bundled modules. */ | |
| import {readFileSync,writeFileSync,statSync} from 'node:fs'; | |
| import {build} from 'esbuild'; | |
| const data=readFileSync('data.json','utf8'); | |
| JSON.parse(data); // fail fast on an invalid snapshot | |
| const result=await build({entryPoints:['app.mjs'],bundle:true,format:'iife',minify:true,target:['es2020'],write:false,legalComments:'none',logLevel:'warning'}); | |
| const bundle=result.outputFiles[0].text; | |
| let html=readFileSync('source.html','utf8'); | |
| const css=readFileSync('style.css','utf8'); | |
| html=html.replace('<link rel="stylesheet" href="style.css">',()=>`<style>${css}</style>`); | |
| html=html.replace('<script type="module" src="app.mjs"></script>',()=>`<script>window.ASCEND_DATA=${data.replace(/<\/script/gi,'<\\/script')};</script>\n<script>${bundle}</script>`); | |
| if(!html.includes('window.ASCEND_DATA=')||!html.includes('<style>'))throw new Error('inlining failed'); | |
| writeFileSync('index.html',html); | |
| console.log(`index.html ${(statSync('index.html').size/1024).toFixed(0)} kB · bundle ${(bundle.length/1024).toFixed(0)} kB · data ${(data.length/1024).toFixed(0)} kB`); | |