Files
pixelheros/extensions/pixelhero-config-editor/esbuild.config.mjs
panFD 24b5c49891 feat(config-editor): extension entry + minimal Vue panel proving end-to-end IPC
Task 12 of plan 2026-06-20-config-editor-foundation. Adds:
- src/main/index.ts: onLoad + message handlers (return value = request resolve,
  per Cocos 3.x verified IPC mechanism; fallback note left in plan)
- src/panels/default/{index,app}.ts: Editor.Panel.define host + Vue 3 minimal
  app (table switcher, key list, record JSON dump)
- static/template/default/index.html + static/style/default/index.css

Deviation from plan (necessary, flagged): esbuild.config.mjs now marks
node:fs/node:path as external for the panel entry (platform:'browser').
The plan's panel reads static template/style at runtime via Node fs, which
requires these builtins; Cocos panel runs in an Electron renderer that
provides them. Without this, esbuild errors with 'Could not resolve node:fs'.

Build verified: dist/main.js (9.5mb, typescript compiler API bundled) and
dist/panels/default.js (628kb, vue.esm-bundler bundled) both generate.
2026-06-21 09:56:02 +08:00

30 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { build, context } from 'esbuild';
import { readFileSync } from 'fs';
import { join } from 'path';
const watch = process.argv.includes('--watch');
const common = {
bundle: true,
sourcemap: false,
logLevel: 'info',
alias: { 'vue': 'vue/dist/vue.esm-bundler.js' },
};
// 面板进程在 Cocos 的 Electron 渲染层运行,可访问 Node 内建fs/path但 vue 必须
// 打进浏览器侧 IIFE。因此面板项用 platform:'browser' + 把 node: 内建标为 external
// 交由运行时解析;这样 esbuild 既不抱怨,又保持 plan 的"运行时读 static 文件"语义。
const entries = [
{ entryPoints: ['src/main/index.ts'], outfile: 'dist/main.js', platform: 'node', format: 'cjs', external: [] },
{ entryPoints: ['src/panels/default/index.ts'], outfile: 'dist/panels/default.js', platform: 'browser', format: 'iife', external: ['node:fs', 'node:path'] },
];
if (watch) {
for (const e of entries) {
const ctx = await context({ ...common, ...e });
await ctx.watch();
}
} else {
for (const e of entries) await build({ ...common, ...e });
}