Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(export): join a project platform's two halves, so a vendor can replace a capability

yhh676c10d6d4c2
diff --git a/desktop/electron/exportMiniGame.ts b/desktop/electron/exportMiniGame.ts
index 1c4cf77a8..5075bebbc 100644
--- a/desktop/electron/exportMiniGame.ts
+++ b/desktop/electron/exportMiniGame.ts
@@ -295,10 +295,18 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
// runtime must instantiate the staged glue's .wasm twin, not guess a name.
const engineWasmPath = `wasm/${engineGlueFile.replace(/\.js$/, '.wasm')}`;
const themeColors = opts.uiThemeColors && Object.keys(opts.uiThemeColors).length > 0 ? opts.uiThemeColors : undefined;
+ // A vendor whose SDK entry does not install a platform on import (the
+ // family entry, esengine/minigame — it waits until the game names a host)
+ // gets its runtime profile installed here, at the top of boot(). Without
+ // this the package would build fine and then throw on the device, which is
+ // the worst place to learn that the two halves of a vendor were never joined.
+ const installsPlatform = !!profile.runtimeProfileModule;
const entrySrc =
- `import { ${profile.runtimeInit}${themeColors ? ', parseThemeOverrides' : ''} } from 'esengine';\n` +
+ `import { ${profile.runtimeInit}${installsPlatform ? ', installMiniGamePlatform' : ''}${themeColors ? ', parseThemeOverrides' : ''} } from 'esengine';\n` +
+ (installsPlatform ? `import __platformProfile from ${JSON.stringify(profile.runtimeProfileModule)};\n` : '') +
(scriptsAbs && existsSync(scriptsAbs) ? `import ${JSON.stringify(scriptsAbs)};\n` : '') +
`export function boot(engineFactory, sideModuleFactories) {\n` +
+ (installsPlatform ? ` installMiniGamePlatform(__platformProfile);\n` : '') +
` return ${profile.runtimeInit}({ engineFactory, engineWasmPath: ${JSON.stringify(engineWasmPath)}, sideModuleFactories, sceneNames: ${JSON.stringify(scenes.map((s) => s.name))}, firstScene: ${JSON.stringify(sceneName)}${opts.ySortLayers ? `, ySortLayers: ${opts.ySortLayers >>> 0}` : ''}${opts.colorSpace === 'linear' ? `, colorSpace: 'linear'` : ''}${opts.screenFit && opts.screenFit.scaleMode >= 0 ? `, screenFit: ${JSON.stringify(opts.screenFit)}` : ''}${opts.uiTheme === 'light' ? `, uiTheme: 'light'` : ''}${themeColors ? `, uiThemeOverrides: parseThemeOverrides(${JSON.stringify(themeColors)})` : ''} });\n` +
`}\n`;
progress({ phase: 'Bundling game' });
diff --git a/desktop/electron/miniGameExportProfile.ts b/desktop/electron/miniGameExportProfile.ts
index 8569ab6d7..d62e78271 100644
--- a/desktop/electron/miniGameExportProfile.ts
+++ b/desktop/electron/miniGameExportProfile.ts
@@ -87,6 +87,20 @@ export interface MiniGameExportProfile {
/** Subpackage root prefix (files stage under `<subpackageDir>/<name>/`). */
readonly subpackageDir: string;
+ /**
+ * Absolute path of a module whose DEFAULT EXPORT is the runtime
+ * `MiniGameProfile` — the host global plus any capability this vendor
+ * overrides (its own video decoder, audio backend, socket, wasm loader).
+ *
+ * A vendor has two halves: this file describes PACKAGING, and that module
+ * describes the RUNTIME. The built-in WeChat entry installs its own platform
+ * on import, so it needs none; a project platform boots through
+ * `esengine/minigame`, which deliberately installs nothing until the game
+ * names a host — so the generated entry installs this one before booting.
+ * Absent ⇒ the game is expected to install a platform itself.
+ */
+ readonly runtimeProfileModule?: string;
+
/** Emit the vendor config files (game.json + project.config.json / project.tt.json). */
emitConfigFiles(ctx: MiniGameConfigContext): Array<{ file: string; content: string }>;
/** Emit the MiniGame entry the host runs (game.js). */
diff --git a/desktop/electron/platformCatalog.ts b/desktop/electron/platformCatalog.ts
index 359efd0fd..d99e81b33 100644
--- a/desktop/electron/platformCatalog.ts
+++ b/desktop/electron/platformCatalog.ts
@@ -144,6 +144,16 @@ export interface ProjectPlatformModule extends Partial<MiniGameExportProfile> {
/** Engine runtime dir for this platform, relative to the project root.
* Absent → the editor's web runtime. */
wasmDir?: string;
+ /**
+ * Project-relative module whose default export is the RUNTIME
+ * `MiniGameProfile`: `{ id, hostLabel, global }` plus any capability this
+ * vendor replaces — its own video decoder, audio backend, socket or wasm
+ * loader. The generated entry installs it before booting.
+ *
+ * This file is the packaging half of a vendor; that module is the runtime
+ * half. Naming it here is what joins them.
+ */
+ runtimeProfile?: string;
emitConfigFiles(ctx: MiniGameConfigContext): Array<{ file: string; content: string }>;
}
@@ -211,7 +221,13 @@ export async function loadProjectPlatform(root: string, id: string, dirs: Platfo
for (const file of await projectPlatformFiles(root)) {
const { mod } = await importPlatformModule(file);
if (!mod || mod.id !== id) continue;
- const profile = { ...MINIGAME_PROFILE_DEFAULTS, ...mod } as MiniGameExportProfile;
+ // The runtime half is resolved to an absolute path here: the generated entry
+ // is bundled with `resolveDir` at the project root, but an absolute specifier
+ // is unambiguous whatever the profile wrote.
+ const runtimeProfileModule = mod.runtimeProfile
+ ? (path.isAbsolute(mod.runtimeProfile) ? mod.runtimeProfile : path.join(root, mod.runtimeProfile))
+ : undefined;
+ const profile = { ...MINIGAME_PROFILE_DEFAULTS, ...mod, runtimeProfileModule } as MiniGameExportProfile;
const wasmDir = mod.wasmDir
? (path.isAbsolute(mod.wasmDir) ? mod.wasmDir : path.join(root, mod.wasmDir))
: dirs.web;
@@ -252,6 +268,21 @@ export async function listPlatforms(root: string | null, dirs: PlatformRuntimeDi
const wasmDir = mod.wasmDir
? (path.isAbsolute(mod.wasmDir) ? mod.wasmDir : path.join(root, mod.wasmDir))
: dirs.web;
+ // A runtime half that points nowhere is caught here rather than on a device:
+ // the export would bundle fine and then fail to resolve the import.
+ if (mod.runtimeProfile) {
+ const abs = path.isAbsolute(mod.runtimeProfile) ? mod.runtimeProfile : path.join(root, mod.runtimeProfile);
+ if (![abs, `${abs}.ts`, `${abs}.js`, `${abs}.mjs`].some(existsSync)) {
+ out.push({
+ id: mod.id,
+ source: 'project',
+ ready: false,
+ label: mod.label,
+ error: `runtimeProfile "${mod.runtimeProfile}" does not exist`,
+ });
+ continue;
+ }
+ }
const glues = mod.engineGlueCandidates ?? MINIGAME_PROFILE_DEFAULTS.engineGlueCandidates;
const ready = glues.some((g) => existsSync(path.join(wasmDir, g)));
out.push({
diff --git a/desktop/tests/export-project-platform.test.ts b/desktop/tests/export-project-platform.test.ts
new file mode 100644
index 000000000..60c2a9103
--- /dev/null
+++ b/desktop/tests/export-project-platform.test.ts
@@ -0,0 +1,155 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+//
+// Exporting for a platform the EDITOR DOES NOT SHIP: the project supplies a
+// profile and the vendor-neutral mini-game pipeline runs with it.
+//
+// The case worth pinning down is the join between a vendor's two halves. The
+// packaging profile is data; the runtime profile is where the host global and
+// any replaced capability live (a game writing its own video decoder puts it
+// there). They are separate objects in separate processes, and the generated
+// entry is the only thing that can bring them together — `esengine/minigame`
+// deliberately installs no platform until the game names a host, so if the entry
+// does not install one, the package builds cleanly and then throws on device.
+import { describe, it, expect, beforeAll, afterAll } from 'vitest';
+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
+import { exportGame } from '../electron/exportGame';
+import { loadProjectPlatform } from '../electron/platformCatalog';
+
+const TEX = '11111111-1111-4111-8111-111111111111';
+const SCN = '22222222-2222-4222-8222-222222222222';
+
+const meta = (uuid: string, type: string) => JSON.stringify({ uuid, type, importer: {} });
+
+let root: string;
+let out: string;
+
+beforeAll(() => {
+ root = mkdtempSync(path.join(tmpdir(), 'es-projplat-'));
+
+ mkdirSync(path.join(root, 'assets'), { recursive: true });
+ writeFileSync(path.join(root, 'assets', 'hero.png'), 'PNGDATA');
+ writeFileSync(path.join(root, 'assets', 'hero.png.meta'), meta(TEX, 'texture'));
+
+ mkdirSync(path.join(root, 'scenes'), { recursive: true });
+ writeFileSync(
+ path.join(root, 'scenes', 'main.esscene'),
+ JSON.stringify({ version: '1.0', name: 'Main', entities: [{ id: 0, components: [{ type: 'Sprite', data: { texture: `@uuid:${TEX}` } }] }] }),
+ );
+ writeFileSync(path.join(root, 'scenes', 'main.esscene.meta'), meta(SCN, 'scene'));
+
+ // The runtime half: the host global plus a capability this vendor replaces.
+ mkdirSync(path.join(root, 'src'), { recursive: true });
+ writeFileSync(path.join(root, 'src', 'acme-runtime.js'), `
+export default {
+ id: 'acme-play',
+ hostLabel: 'ACME Play',
+ get global() { return globalThis.acme; },
+ // The point of the exercise: this vendor ships its own video decoding.
+ createVideoBackend(ctx) { return { name: 'acme-software', createStream() {}, dispose() {} }; },
+};
+`);
+
+ // The packaging half, naming the runtime one.
+ mkdirSync(path.join(root, '.esengine', 'platforms'), { recursive: true });
+ writeFileSync(path.join(root, '.esengine', 'platforms', 'acme-play.mjs'), `
+export default {
+ id: 'acme-play',
+ label: 'ACME Play',
+ defaultOut: 'dist-acme',
+ runtimeProfile: 'src/acme-runtime.js',
+ emitConfigFiles(ctx) {
+ return [{ file: 'game.json', content: JSON.stringify({ appName: ctx.title, orientation: ctx.orientation }) + '\\n' }];
+ },
+};
+`);
+
+ // Stub SDK dist: the bundle aliases `esengine` → <sdkDir>/index.minigame.js,
+ // the family entry that installs nothing on import.
+ mkdirSync(path.join(root, '_sdk'), { recursive: true });
+ writeFileSync(
+ path.join(root, '_sdk', 'index.minigame.js'),
+ `export function initMiniGameRuntime(){return Promise.resolve();}\nexport function installMiniGamePlatform(){}\nexport function defineComponent(){}\n`,
+ );
+ // Stub engine runtime — the default glue candidate is the standard esengine.js.
+ mkdirSync(path.join(root, '_wasm'), { recursive: true });
+ writeFileSync(path.join(root, '_wasm', 'esengine.js'), 'module.exports = () => Promise.resolve({});');
+ writeFileSync(path.join(root, '_wasm', 'esengine.wasm'), 'wasmbytes');
+
+ out = path.join(root, 'dist-acme');
+}, 60_000);
+
+afterAll(() => rmSync(root, { recursive: true, force: true }));
+
+describe('exportGame — a platform the project defines', () => {
+ it('packages through the mini-game pipeline and joins the vendor\'s two halves', async () => {
+ const platform = await loadProjectPlatform(root, 'acme-play', { web: path.join(root, '_wasm'), wechat: path.join(root, '_wasm') });
+ expect(platform).not.toBeNull();
+
+ const res = await exportGame({
+ root,
+ entryScene: 'scenes/main.esscene',
+ gameHostEntry: 'unused',
+ sdkDistDir: path.join(root, '_sdk'),
+ wasmDir: platform!.wasmDir,
+ outDir: out,
+ title: 'ACME Game',
+ platform: 'acme-play',
+ miniGameProfile: platform!.profile,
+ orientation: 'portrait',
+ });
+
+ expect(res.errors).toEqual([]);
+ expect(res.ok).toBe(true);
+ // The result carries the project's id — which is also the cook's per-platform
+ // Import Settings key, so this vendor's texture overrides would apply.
+ expect(res.platform).toBe('acme-play');
+
+ // The project's own config emitter ran.
+ const gameJson = JSON.parse(readFileSync(path.join(out, 'game.json'), 'utf8'));
+ expect(gameJson).toEqual({ appName: 'ACME Game', orientation: 'portrait' });
+
+ // The default entry emitter ran (no vendor override needed for game.js).
+ const entry = readFileSync(path.join(out, 'game.js'), 'utf8');
+ expect(entry).toContain("require('./wasm/esengine.js')");
+ expect(entry).toContain("require('./game-bundle.js')");
+
+ // THE JOIN: the bundle installs the runtime profile before booting, and the
+ // vendor's replaced capability rode in with it.
+ const bundle = readFileSync(path.join(out, 'game-bundle.js'), 'utf8');
+ expect(bundle).toContain('installMiniGamePlatform');
+ expect(bundle).toContain('acme-software');
+ expect(bundle).toContain('initMiniGameRuntime');
+
+ // Scene + manifest assembled the same way as any other mini-game target.
+ expect(readFileSync(path.join(out, 'scenes', 'Main.json'), 'utf8')).toContain(TEX);
+ expect(readFileSync(path.join(out, 'asset-manifest.json'), 'utf8')).toContain(TEX);
+ }, 60_000);
+
+ it('omits the install when the project installs its own platform', async () => {
+ // Same vendor, minus the runtimeProfile link: the game is then responsible
+ // for calling installMiniGamePlatform itself, so the entry must not guess.
+ const bare = { ...(await loadProjectPlatform(root, 'acme-play', { web: path.join(root, '_wasm'), wechat: path.join(root, '_wasm') }))!.profile };
+ delete (bare as { runtimeProfileModule?: string }).runtimeProfileModule;
+
+ const outBare = path.join(root, 'dist-bare');
+ const res = await exportGame({
+ root,
+ entryScene: 'scenes/main.esscene',
+ gameHostEntry: 'unused',
+ sdkDistDir: path.join(root, '_sdk'),
+ wasmDir: path.join(root, '_wasm'),
+ outDir: outBare,
+ title: 'ACME Game',
+ platform: 'acme-play',
+ miniGameProfile: bare,
+ });
+
+ expect(res.ok).toBe(true);
+ const bundle = readFileSync(path.join(outBare, 'game-bundle.js'), 'utf8');
+ expect(bundle).not.toContain('installMiniGamePlatform');
+ expect(bundle).toContain('initMiniGameRuntime');
+ }, 60_000);
+});
diff --git a/desktop/tests/platform-catalog.test.ts b/desktop/tests/platform-catalog.test.ts
index 4cc24aca7..b39c3475f 100644
--- a/desktop/tests/platform-catalog.test.ts
+++ b/desktop/tests/platform-catalog.test.ts
@@ -186,6 +186,50 @@ describe('loadProjectPlatform — the profile handed to exportMiniGame', () => {
expect((await loadProjectPlatform(root, 'b', dirs()))!.defaultOut).toBe('dist-b');
});
+ // A vendor has two halves: the .mjs describes packaging, a runtime module
+ // describes the host (and any capability it replaces — its own video decoder,
+ // audio backend, socket). Naming the second from the first is what joins them,
+ // and the generated entry installs it before booting.
+ it('resolves the runtime half to an absolute module path', async () => {
+ mkdirSync(path.join(root, 'src'), { recursive: true });
+ writeFileSync(path.join(root, 'src', 'acme-runtime.ts'), 'export default {};');
+ writePlatform('acme.mjs', `export default {
+ id: 'acme', label: 'ACME Play', runtimeProfile: 'src/acme-runtime.ts',
+ emitConfigFiles: () => [],
+ };`);
+
+ const loaded = await loadProjectPlatform(root, 'acme', dirs());
+ expect(loaded!.profile.runtimeProfileModule).toBe(path.join(root, 'src', 'acme-runtime.ts'));
+ });
+
+ it('leaves runtimeProfileModule undefined when the project installs its own platform', async () => {
+ writePlatform('acme.mjs', `export default { id: 'acme', label: 'A', emitConfigFiles: () => [] };`);
+ const loaded = await loadProjectPlatform(root, 'acme', dirs());
+ expect(loaded!.profile.runtimeProfileModule).toBeUndefined();
+ });
+
+ it('flags a runtime half that points nowhere, instead of shipping a broken import', async () => {
+ writePlatform('acme.mjs', `export default {
+ id: 'acme', label: 'ACME Play', runtimeProfile: 'src/missing.ts',
+ emitConfigFiles: () => [],
+ };`);
+ const acme = (await listPlatforms(root, dirs())).find((r) => r.id === 'acme');
+ expect(acme!.ready).toBe(false);
+ expect(acme!.error).toContain('runtimeProfile');
+ });
+
+ it('accepts a runtime half written without its extension', async () => {
+ mkdirSync(path.join(root, 'src'), { recursive: true });
+ writeFileSync(path.join(root, 'src', 'rt.ts'), 'export default {};');
+ writePlatform('acme.mjs', `export default {
+ id: 'acme', label: 'A', runtimeProfile: 'src/rt', emitConfigFiles: () => [],
+ };`);
+ writeFileSync(path.join(webDir, 'esengine.js'), '//');
+ const acme = (await listPlatforms(root, dirs())).find((r) => r.id === 'acme');
+ expect(acme!.error).toBeUndefined();
+ expect(acme!.ready).toBe(true);
+ });
+
it('is null for a built-in id, so the built-in pipeline keeps it', async () => {
expect(await loadProjectPlatform(root, 'wechat', dirs())).toBeNull();
expect(await loadProjectPlatform(root, 'nope', dirs())).toBeNull();
diff --git a/docs/astro/src/content/docs/guides/minigame-platforms.mdx b/docs/astro/src/content/docs/guides/minigame-platforms.mdx
index 83a4394ee..4e209b205 100644
--- a/docs/astro/src/content/docs/guides/minigame-platforms.mdx
+++ b/docs/astro/src/content/docs/guides/minigame-platforms.mdx
@@ -67,6 +67,55 @@ same way. Override one only where the host genuinely differs; the defaults are
`MiniGameAudioBackend`, the wasm video decoder, and `MiniGameSocket`, all
exported from `esengine/minigame` so you can wrap rather than rewrite.
+## Replacing one capability
+
+The optional methods are not only for host differences — they are the seam for
+replacing an implementation you don't want. Writing your own video decoding, for
+example, is one method:
+
+```ts
+import type { MiniGameProfile, PlatformVideoBackend, VideoBackendContext } from 'esengine/minigame';
+
+class SoftwareVideoBackend implements PlatformVideoBackend {
+ readonly name = 'my-software-decoder';
+ constructor(private ctx: VideoBackendContext) {}
+ createStream(url: string, options) { /* your decode → VideoStreamHandle */ }
+ dispose() {}
+}
+
+export default {
+ id: 'myvendor',
+ hostLabel: 'MyVendor',
+ get global() { return myHost; },
+ createVideoBackend: (ctx) => new SoftwareVideoBackend(ctx),
+} satisfies MiniGameProfile;
+```
+
+`VideoPlugin` asks the platform for a backend once at build; whatever you return
+is what every `VideoPlayer` in the game drives. The contract to satisfy is
+`PlatformVideoBackend` — `createStream(url, options)` returning a
+`VideoStreamHandle` whose `pump(module)` uploads the current frame to
+`textureHandle` once per frame. Audio (`PlatformAudioBackend`) and sockets
+(`PlatformSocket`) work the same way.
+
+To keep most of a host and change one thing, spread its profile:
+
+```ts
+import { wechatProfile } from 'esengine/wechat';
+
+export default { ...wechatProfile, createVideoBackend: (ctx) => new SoftwareVideoBackend(ctx) };
+```
+
+<Aside type="caution">
+ This replaces a capability of **a platform you install yourself**. The built-in
+ targets install their own profile on import, so selecting *WeChat* in Package
+ Project always gets the stock backends — to ship a modified one, define it as a
+ project platform (below) and select that instead. Spreading `wechatProfile`
+ also does not carry WeChat's `WXWebAssembly` polyfill, which
+ `initWeChatPlatform()` installs; call `polyfillWebAssembly()` from
+ `esengine/wechat` yourself if you go that route.
+</Aside>
+
## What the host must provide
Your `global` has to satisfy `MiniGameGlobal`. Required:
@@ -166,6 +215,39 @@ standard mini-game host: the vendor-neutral SDK entry (`index.minigame.js`),
CommonJS `game.js`. Everything else — cook, manifest, scene transform,
side-module scan, bundling, runtime copy — is the same pipeline WeChat uses.
+### A vendor has two halves
+
+The file above is the **packaging** half. The **runtime** half is the
+`MiniGameProfile` from the first part of this guide — the host global, and any
+capability you replace. Point at it with `runtimeProfile` and the generated entry
+installs it before booting:
+
+```js
+// .esengine/platforms/acme-play.mjs
+export default {
+ id: 'acme-play',
+ label: 'ACME Play',
+ runtimeProfile: 'src/acme-runtime.ts', // ← the other half
+ emitConfigFiles(ctx) { /* … */ },
+};
+```
+
+```ts
+// src/acme-runtime.ts — default-exports the runtime MiniGameProfile
+export default {
+ id: 'acme-play',
+ hostLabel: 'ACME Play',
+ get global() { return acme; },
+ createVideoBackend: (ctx) => new SoftwareVideoBackend(ctx),
+};
+```
+
+This link matters because `esengine/minigame` installs no platform until the game
+names a host. Without it the package builds cleanly and then throws on the
+device. Omit `runtimeProfile` only if your game calls `installMiniGamePlatform`
+itself; the editor checks the path exists and refuses to call the platform ready
+otherwise.
+
The `id` must be lowercase letters/digits/dashes and must not shadow a built-in.
It is also the cook's **Import Settings key**, so per-texture compression
overrides can target your platform by name.
@@ -193,6 +275,7 @@ Everything you can override, and what the pipeline uses it for:
| `subpackageDir` | where lazy groups stage |
| `emitConfigFiles` / `emitEntry` | the vendor's config files and `game.js` |
| `wasmDir` | project-relative engine runtime dir (default: the editor's web runtime) |
+| `runtimeProfile` | project-relative module default-exporting the runtime `MiniGameProfile` |
<Aside type="note">
The profile module runs in the editor's **main process**, not the renderer —
diff --git a/docs/astro/src/content/docs/zh-cn/guides/minigame-platforms.mdx b/docs/astro/src/content/docs/zh-cn/guides/minigame-platforms.mdx
index 76caf30aa..6b8c62097 100644
--- a/docs/astro/src/content/docs/zh-cn/guides/minigame-platforms.mdx
+++ b/docs/astro/src/content/docs/zh-cn/guides/minigame-platforms.mdx
@@ -62,6 +62,50 @@ WASM 实例化。微信走 `WXWebAssembly.instantiate(path)` 而不是标准 `We
**确实**不同的地方覆盖;默认实现是 `MiniGameAudioBackend`、wasm 视频解码器和
`MiniGameSocket`,它们都从 `esengine/minigame` 导出,你可以包装而不必重写。
+## 替换单个能力
+
+这几个可选方法不只用于「宿主有差异」——它们就是**替换你不满意的实现**的接缝。
+比如自己写一套视频软解码,只需要一个方法:
+
+```ts
+import type { MiniGameProfile, PlatformVideoBackend, VideoBackendContext } from 'esengine/minigame';
+
+class SoftwareVideoBackend implements PlatformVideoBackend {
+ readonly name = 'my-software-decoder';
+ constructor(private ctx: VideoBackendContext) {}
+ createStream(url: string, options) { /* 你的解码 → VideoStreamHandle */ }
+ dispose() {}
+}
+
+export default {
+ id: 'myvendor',
+ hostLabel: 'MyVendor',
+ get global() { return myHost; },
+ createVideoBackend: (ctx) => new SoftwareVideoBackend(ctx),
+} satisfies MiniGameProfile;
+```
+
+`VideoPlugin` 在 build 时向平台要一次后端,你返回什么,游戏里所有 `VideoPlayer`
+就驱动什么。要满足的契约是 `PlatformVideoBackend`:`createStream(url, options)`
+返回一个 `VideoStreamHandle`,它的 `pump(module)` 每帧把当前帧上传到
+`textureHandle`。音频(`PlatformAudioBackend`)和 socket(`PlatformSocket`)同理。
+
+想保留某个宿主的大部分、只换其中一件,把它的 profile 展开:
+
+```ts
+import { wechatProfile } from 'esengine/wechat';
+
+export default { ...wechatProfile, createVideoBackend: (ctx) => new SoftwareVideoBackend(ctx) };
+```
+
+<Aside type="caution">
+ 这替换的是**你自己安装的平台**的能力。内置目标在 import 时就装好了自己的 profile,
+ 所以在打包对话框里选「微信小游戏」拿到的永远是原装后端——要发布改过的版本,
+ 请把它定义成一个项目平台(见下)并改选它。另外展开 `wechatProfile` 不会带上
+ `initWeChatPlatform()` 装的 `WXWebAssembly` polyfill,走这条路要自己调
+ `esengine/wechat` 的 `polyfillWebAssembly()`。
+</Aside>
+
## 宿主需要提供什么
你的 `global` 需要满足 `MiniGameGlobal`。必需成员:
@@ -157,6 +201,37 @@ export default {
`WebAssembly` 引擎 glue,以及通用的 CommonJS `game.js`。剩下的一切——cook、
manifest、场景变换、side-module 扫描、打包、运行时拷贝——与微信走的是同一条管线。
+### 一个平台有两半
+
+上面这个文件是**打包**那一半。**运行时**那一半就是本指南开头的 `MiniGameProfile`
+——宿主全局对象,以及你替换掉的任何能力。用 `runtimeProfile` 指过去,生成的入口
+就会在启动前把它装上:
+
+```js
+// .esengine/platforms/acme-play.mjs
+export default {
+ id: 'acme-play',
+ label: 'ACME Play',
+ runtimeProfile: 'src/acme-runtime.ts', // ← 另一半
+ emitConfigFiles(ctx) { /* … */ },
+};
+```
+
+```ts
+// src/acme-runtime.ts —— 默认导出运行时 MiniGameProfile
+export default {
+ id: 'acme-play',
+ hostLabel: 'ACME Play',
+ get global() { return acme; },
+ createVideoBackend: (ctx) => new SoftwareVideoBackend(ctx),
+};
+```
+
+这个连接很关键:`esengine/minigame` 在游戏指明宿主之前不装任何平台。没有它,
+包能正常构建,然后在设备上抛错。只有当你的游戏自己调用 `installMiniGamePlatform`
+时才可以省略 `runtimeProfile`;编辑器会检查这个路径是否存在,不存在就不会把该平台
+标为就绪。
+
`id` 只能是小写字母/数字/短横线,且不能与内置平台重名。它同时是 cook 的
**导入设置键**,所以逐纹理的压缩覆盖可以按名字指定你的平台。
@@ -182,6 +257,7 @@ manifest、场景变换、side-module 扫描、打包、运行时拷贝——与
| `subpackageDir` | 懒加载分组落盘的位置 |
| `emitConfigFiles` / `emitEntry` | 该平台的配置文件与 `game.js` |
| `wasmDir` | 相对项目的引擎运行时目录(默认用编辑器自带的 web 运行时) |
+| `runtimeProfile` | 相对项目的模块路径,默认导出运行时 `MiniGameProfile` |
<Aside type="note">
profile 模块跑在编辑器的**主进程**里,而不是渲染进程——它的 emitter 是函数,