// 引擎单文件打包(开发用):把 plugin/engine.js + potrace 打成 IIFE 全局 VZEngine,便于在 // 浏览器里直接跑参数实验(tools/trace-cli.mjs 用它)。发布不走这里 —— 发布走根目录 // scripts/build-plugin.mjs(esbuild → 单文件 IIFE 插件)。 import path from 'node:path' import { fileURLToPath } from 'node:url' import { createRequire } from 'node:module' const HERE = path.dirname(fileURLToPath(import.meta.url)) const PLUGIN = path.resolve(HERE, '../plugin') const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web' const REPO = path.resolve(HERE, '../..') export function esbuildModule() { for (const base of [HOST_REPO, REPO, process.cwd()]) { try { return createRequire(path.join(base, 'package.json'))('esbuild') } catch { /* 试下一个 */ } } throw new Error('找不到 esbuild(宿主仓 node_modules 里应该有)') } export function bundleEngine(outfile = '/tmp/vz-engine.bundle.js') { const esbuild = esbuildModule() esbuild.buildSync({ entryPoints: [path.join(PLUGIN, 'engine.js')], bundle: true, format: 'iife', globalName: 'VZEngine', platform: 'browser', target: ['chrome110'], outfile, logLevel: 'error', }) return outfile }