mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 08:37:56 +00:00
Docs: Update benchmark for test 4
This commit is contained in:
@@ -1,36 +1,5 @@
|
||||
const bundleApp = async (entry, files) => {
|
||||
const { transform } = await import('https://esm.sh/@babel/standalone');
|
||||
let id = 0, queue = [{ name: entry, id: id++ }], modules = [];
|
||||
|
||||
for (const asset of queue) {
|
||||
if (files[asset.name] == null) throw new Error(`Missing file: ${asset.name}`);
|
||||
|
||||
const { code } = transform(files[asset.name], { presets: ['env'] });
|
||||
const map = {};
|
||||
|
||||
code.replace(/require\s*\(\s*['"](.+?)['"]\s*\)/g, (_, path) => {
|
||||
const base = asset.name.split('/'), rel = path.split('/');
|
||||
base.pop();
|
||||
rel.forEach(p => p === '..' ? base.pop() : p !== '.' && base.push(p));
|
||||
const abs = base.join('/');
|
||||
|
||||
let child = queue.find(x => x.name === abs);
|
||||
if (!child) queue.push(child = { name: abs, id: id++ });
|
||||
map[path] = child.id;
|
||||
});
|
||||
|
||||
modules.push(`${asset.id}:[function(require,module,exports){${code}},${JSON.stringify(map)}]`);
|
||||
}
|
||||
|
||||
return `;(function(m){
|
||||
var c={};
|
||||
function r(i){
|
||||
if(c[i])return c[i].exports;
|
||||
var mod=c[i]={exports:{}}, fn=m[i][0], map=m[i][1];
|
||||
fn(p=>r(map[p]||p), mod, mod.exports);
|
||||
return mod.exports;
|
||||
}
|
||||
return r(0);
|
||||
})({${modules.join(',')}})`;
|
||||
};
|
||||
export default bundleApp;
|
||||
const renderTemplate = async (tmpl, data) => {
|
||||
const { default: H } = await import('https://cdn.jsdelivr.net/npm/handlebars@latest/+esm')
|
||||
return H.compile(tmpl)(data)
|
||||
}
|
||||
export default renderTemplate;
|
||||
Reference in New Issue
Block a user