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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(export): a web package carries the SDK it can load, not all five
yhh79345e347416
diff --git a/desktop/electron/exportGame.ts b/desktop/electron/exportGame.tsindex 61076b7b5..677ec47c2 100644--- a/desktop/electron/exportGame.ts+++ b/desktop/electron/exportGame.ts@@ -123,6 +123,33 @@ export async function discoverProjectScenes(root: string, entryScene: string, screturn scenes;}+/**+ * Entry bundles in sdk/dist that a BROWSER page can never load: the other+ * platforms' builds. `dist` holds every target's output side by side, and the+ * export used to copy the tree wholesale — so a web package shipped the Node,+ * WeChat, mini-game and native SDKs, each with a multi-megabyte source map, next+ * to the one the import map actually names.+ */+const OTHER_PLATFORM_ENTRIES = /^index\.(node|wechat|wechat\.cjs|minigame|native|native\.bundled|bundled)\.js(\.map)?$/;++/**+ * Whether a file under sdk/dist belongs in a browser package.+ *+ * Directories always pass — the per-file test decides what lands inside them,+ * and refusing a directory would drop the shared chunks the entry imports.+ * Type declarations go too: nothing at runtime reads a `.d.ts`, and they are a+ * megabyte of a package whose whole point is what the player downloads.+ *+ * Deliberately a name test rather than a walk of the import graph: the graph+ * would be exact but silent when it is wrong, and a bundle this drops that+ * something did want is a 404 the moment the page loads, not a subtle bug.+ */+export function shipsToBrowser(src: string): boolean {+ const base = path.basename(src);+ if (base.endsWith('.d.ts')) return false;+ return !OTHER_PLATFORM_ENTRIES.test(base);+}+/*** Warn about content this target cannot render. The editor authors every* subsystem the engine has, but a target may compile only some of them (the@@ -707,10 +734,12 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>// 4. SDK (import-map target) + wasm runtime. The import map and the game// host reference both unconditionally — a missing tree is not a degraded// export but a package that cannot boot, so it fails the export.+ // Filtered, because sdk/dist holds every platform's build side by side.if (!nativeContent) {progress({ phase: 'Copying SDK + runtime' });- if (existsSync(opts.sdkDistDir)) await cp(opts.sdkDistDir, path.join(payloadDir, 'sdk'), { recursive: true });- else errors.push(`sdk dist not found: ${opts.sdkDistDir}`);+ if (existsSync(opts.sdkDistDir)) {+ await cp(opts.sdkDistDir, path.join(payloadDir, 'sdk'), { recursive: true, filter: shipsToBrowser });+ } else errors.push(`sdk dist not found: ${opts.sdkDistDir}`);if (existsSync(opts.wasmDir)) await cp(opts.wasmDir, path.join(payloadDir, 'wasm'), { recursive: true });else errors.push(`wasm runtime dir not found: ${opts.wasmDir}`);}diff --git a/desktop/tests/export-game.test.ts b/desktop/tests/export-game.test.tsindex 4c60f9115..c5b2ed6de 100644--- a/desktop/tests/export-game.test.ts+++ b/desktop/tests/export-game.test.ts@@ -46,6 +46,17 @@ beforeAll(async () => {// Stand-in SDK dist + wasm runtime dirs to copy.mkdirSync(path.join(root, '_sdk'), { recursive: true });writeFileSync(path.join(root, '_sdk', 'index.js'), 'export const x = 1;');+ writeFileSync(path.join(root, '_sdk', 'index.js.map'), '{"version":3}');+ writeFileSync(path.join(root, '_sdk', 'index.d.ts'), 'export declare const x: number;');+ // sdk/dist holds every target's build side by side; a browser package must not+ // carry the ones it cannot load (each with a multi-megabyte source map).+ for (const dead of [+ 'index.node.js', 'index.node.js.map', 'index.wechat.js', 'index.wechat.cjs.js',+ 'index.wechat.cjs.js.map', 'index.minigame.js', 'index.native.js', 'index.native.bundled.js',+ 'index.bundled.js', 'index.bundled.js.map',+ ]) writeFileSync(path.join(root, '_sdk', dead), '// other platform');+ mkdirSync(path.join(root, '_sdk', 'shared'), { recursive: true });+ writeFileSync(path.join(root, '_sdk', 'shared', 'resource.js'), 'export const r = 1;');mkdirSync(path.join(root, '_wasm'), { recursive: true });writeFileSync(path.join(root, '_wasm', 'esengine.js'), 'export default () => {};');writeFileSync(path.join(root, '_wasm', 'esengine.wasm'), 'wasmbytes');@@ -85,6 +96,18 @@ describe('exportGame', () => {expect(has('game.js')).toBe(true);expect(has('scripts.mjs')).toBe(true);expect(has('sdk/index.js')).toBe(true);+ // The import map's target ships with its chunks and its map; the OTHER+ // platforms' builds and the type declarations do not. Copying sdk/dist+ // wholesale put the Node, WeChat, mini-game and native SDKs — each with a+ // multi-megabyte source map — into a package for a browser.+ expect(has('sdk/index.js.map')).toBe(true);+ expect(has('sdk/shared/resource.js')).toBe(true);+ expect(has('sdk/index.d.ts')).toBe(false);+ for (const dead of [+ 'sdk/index.node.js', 'sdk/index.node.js.map', 'sdk/index.wechat.js', 'sdk/index.wechat.cjs.js',+ 'sdk/index.wechat.cjs.js.map', 'sdk/index.minigame.js', 'sdk/index.native.js',+ 'sdk/index.native.bundled.js', 'sdk/index.bundled.js', 'sdk/index.bundled.js.map',+ ]) expect([dead, has(dead)]).toEqual([dead, false]);expect(has('game.config.json')).toBe(true);// The flat manifest is a build-time intermediate — only the addressable one ships.expect(has('assets.manifest.json')).toBe(false);