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
feat(export): scripts are minified on export unless the project turns it off
yhhba7a0f55e22e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3e4cf33ac..cfbb778b4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -21,6 +21,8 @@ published separately; it ships inside the editor.- **A generated building stands on its ground, and generated roads keep foliage off them.** World generation fits an upright building's base to a grid of ground samples over its whole rotated footprint, and refuses a site that is water, too steep, or rises and falls more than a given relief, reporting how deep the foundation has to reach. Foliage takes the zones a WorldGen world reserves for roads and buildings (and any extra tags) as places it does not grow, with an optional clearance. The world rules editor and the editor's agents can set both.+- **An exported game's scripts are minified, and a WeChat main package is about 0.9MB smaller.** The game and engine JavaScript of a web, mini-game or playable export is now minified unless the project turns off `packaging.minifyScripts` (Project Settings → Packaging → Minify scripts); a development build keeps readable scripts as before. The `ui-controls` example's WeChat main package went from 4.18MB, over the 4MB cap, to 3.27MB.+- **On a phone, a lit 3D scene costs about half as much.** The quality level gains `lighting`. At `low` and `medium`, which a phone takes when the project names no level, every lit mesh and material is compiled as `#pragma lighting direct` asks: the same lighting model with the sixteen lights of the light block and hard shadows, without the lights past them, soft shadows or hair shadows. On a Snapdragon 8 Elite a full-screen lit floor drawn fifteen times over went from 57 to 24 ms a frame under the default soft-shadowed sun, and from 33 to 25 ms under a hard-shadowed one. `high`, and a project with quality off, keep everything. **Project Settings → Rendering → Quality → 3D lighting** changes it per level. Sprites keep their 2D lighting at every level.### Fixeddiff --git a/desktop b/desktopindex 25b02f870..1dc52f201 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 25b02f870a7258686271666e25b3ebb01185bc96+Subproject commit 1dc52f201cda0ea6db714079113e7c90c472da67diff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.tsindex 95361e8b1..37ca7a4a6 100644--- a/pipeline/src/export/exportGame.ts+++ b/pipeline/src/export/exportGame.ts@@ -19,6 +19,7 @@** Pure Node (esbuild + fs) — IPC wiring is in main.ts.*/+import { minifiesScripts } from './scriptMinify';import type { BuildOptions, Plugin } from 'esbuild';import { loadEsbuild } from '../bundle/esbuildRuntime';import { runtimeHostEntry } from '../bundle/runtimeHosts';@@ -588,8 +589,8 @@ export interface ExportGameOptions {* for the differential that proves the two frames agree (REARCH_AOT.md §8.2).*/aotMode?: BuildMode;- /** Shipping config: minify the bundles, no sourcemap. Default off (dev). */minify?: boolean;+ minifyScripts?: boolean;sourcemap?: boolean;/** Where the editor listens for this development build; with `minify`, the* export fails (see `packagedDebugChannel`). */@@ -822,6 +823,7 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>orientation,runtime,minify: opts.minify,+ minifyScripts: opts.minifyScripts,debugChannel: opts.debugChannel,hotUpdate: opts.hotUpdate,emcc: opts.emcc,@@ -864,6 +866,7 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>orientation,runtime,minify: opts.minify,+ minifyScripts: opts.minifyScripts,debugChannel: opts.debugChannel,hotUpdate: opts.hotUpdate,emcc: opts.emcc,@@ -893,6 +896,7 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>title,orientation,minify: opts.minify,+ minifyScripts: opts.minifyScripts,resizeTextures: opts.compressTextures,compressAudio: opts.compressAudio,sizeBudgetBytes: opts.sizeBudgetBytes,@@ -963,7 +967,7 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>target: 'es2020',external: ESENGINE_EXTERNAL,plugins: [officialPackagesPlugin(opts.packagesDir)],- minify: opts.minify ?? false,+ minify: minifiesScripts(opts),sourcemap: sourceMaps,write: true,logLevel: 'silent',diff --git a/pipeline/src/export/exportMiniGame.ts b/pipeline/src/export/exportMiniGame.tsindex 5fbe7ab3c..4805125e2 100644--- a/pipeline/src/export/exportMiniGame.ts+++ b/pipeline/src/export/exportMiniGame.ts@@ -27,6 +27,7 @@* have no import maps and a different module/asset model, so this is its* own path. Pure Node (esbuild + fs) — IPC wiring is in main.ts.*/+import { minifiesScripts } from './scriptMinify';import type { DebugChannelConfig } from 'esengine';import { packagedDebugChannel } from './debugChannel';import { packagedHotUpdate } from './hotUpdateConfig';@@ -283,6 +284,7 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {* generated boot passes the packaged slice of them to the vendor runtime. */runtime?: RuntimeProjectConfig;minify?: boolean;+ minifyScripts?: boolean;debugChannel?: DebugChannelConfig | null;/** Overrides the project's own CDN root / persistence key (see `packagedHotUpdate`). */hotUpdate?: { remoteRoot?: string; persistUpdateKey?: string };@@ -590,7 +592,7 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {target: profile.esTarget,alias: esengineAlias(opts.sdkDir, lean ? leanEntry! : profile.sdkEntryFile),plugins: [officialPackagesPlugin(opts.packagesDir)],- minify: opts.minify ?? false,+ minify: minifiesScripts(opts),sourcemap: false,outfile: path.join(absOut, 'game-bundle.js'),logLevel: 'silent',@@ -635,7 +637,7 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {// the package, this one included.target: profile.esTarget,plugins: [officialPackagesPlugin(opts.packagesDir)],- minify: opts.minify ?? false,+ minify: minifiesScripts(opts),sourcemap: false,outfile: path.join(absOut, OPEN_DATA_DIR, 'index.js'),logLevel: 'silent',diff --git a/pipeline/src/export/exportPlayable.ts b/pipeline/src/export/exportPlayable.tsindex 33179ec8a..0103d9aac 100644--- a/pipeline/src/export/exportPlayable.ts+++ b/pipeline/src/export/exportPlayable.ts@@ -18,6 +18,7 @@* here — runtime is validated in a browser / ad preview). Pure Node (esbuild* + fs); IPC wiring in main.ts.*/+import { minifiesScripts } from './scriptMinify';import { loadEsbuild } from '../bundle/esbuildRuntime';import { runtimeHostEntry } from '../bundle/runtimeHosts';import {@@ -220,6 +221,7 @@ export async function exportPlayable(opts: {* to the pixel). An explicit `false` is still honoured.*/minify?: boolean;+ minifyScripts?: boolean;/** Honor authored PNG Max Size; playables still ship images rather than KTX2. */resizeTextures?: boolean;/** WAV to MP3 at the authored bitrate, honoring each clip's compression opt-out. */@@ -322,7 +324,7 @@ export async function exportPlayable(opts: {// dist; the project root has no esengine installed.alias: esengineAlias(opts.sdkDir),plugins: [officialPackagesPlugin(opts.packagesDir)],- minify: opts.minify ?? true,+ minify: minifiesScripts(opts),write: false,outfile: 'game-bundle.js',logLevel: 'silent',@@ -337,7 +339,7 @@ export async function exportPlayable(opts: {format: 'iife',platform: 'browser',target: 'es2020',- minify: opts.minify ?? true,+ minify: minifiesScripts(opts),write: false,outfile: 'game-loader.js',logLevel: 'silent',diff --git a/pipeline/src/export/scriptMinify.ts b/pipeline/src/export/scriptMinify.tsnew file mode 100644index 000000000..365c5dcf4--- /dev/null+++ b/pipeline/src/export/scriptMinify.ts@@ -0,0 +1,5 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+export function minifiesScripts(opts: { minify?: boolean; minifyScripts?: boolean }): boolean {+ return opts.minify !== false && (opts.minifyScripts ?? true);+}diff --git a/pipeline/src/export/sizeHistory.ts b/pipeline/src/export/sizeHistory.tsindex f706a1985..1a876d587 100644--- a/pipeline/src/export/sizeHistory.ts+++ b/pipeline/src/export/sizeHistory.ts@@ -31,6 +31,7 @@ export interface SizeSettings {compressAudio?: boolean;atlasTextures?: boolean;minify?: boolean;+ minifyScripts?: boolean;sourcemap?: boolean;compressWasm?: boolean;engineSubpackage?: boolean;@@ -48,6 +49,7 @@ export const PACKAGING_SIZE_ROLE: Readonly<Record<string, keyof SizeSettings | 'platform: 'inert',config: 'minify',sourceMaps: 'sourcemap',+ minifyScripts: 'minifyScripts',frameDebugger: 'content',openFolder: 'inert',orientation: 'inert',@@ -77,7 +79,7 @@ export const PACKAGING_SIZE_ROLE: Readonly<Record<string, keyof SizeSettings | 'export function sizeSettingsOf(opts: SizeSettings): SizeSettings {const keys: (keyof SizeSettings)[] = ['contentAddressed', 'compressTextures', 'compressAudio', 'atlasTextures',- 'minify', 'sourcemap', 'compressWasm', 'engineSubpackage', 'profile',+ 'minify', 'minifyScripts', 'sourcemap', 'compressWasm', 'engineSubpackage', 'profile',];const out: Record<string, unknown> = {};for (const k of keys) if (opts[k] !== undefined) out[k] = opts[k];diff --git a/pipeline/src/project/format.ts b/pipeline/src/project/format.tsindex f5eb08848..ba3b0ba43 100644--- a/pipeline/src/project/format.ts+++ b/pipeline/src/project/format.ts@@ -356,6 +356,7 @@ export interface ProjectPackaging {platform?: ExportPlatform;config?: 'development' | 'shipping';sourceMaps?: boolean;+ minifyScripts?: boolean;/** A development build dials the editor so the frame debugger can capture it. */frameDebugger?: boolean;openFolder?: boolean;@@ -486,7 +487,7 @@ export interface ProjectPackaging {/** The packaging settings a profile may set; the rest are the project's. */export const EXPORT_PROFILE_FIELDS = [- 'config', 'sourceMaps', 'assetCompression', 'compressWasm', 'engineSubpackage', 'excludeScenes', 'remoteRoot',+ 'config', 'sourceMaps', 'minifyScripts', 'assetCompression', 'compressWasm', 'engineSubpackage', 'excludeScenes', 'remoteRoot',] as const satisfies readonly (keyof ProjectPackaging)[];/**@@ -922,6 +923,7 @@ export function parseManifest(raw: unknown): ProjectManifest {if (p.config === 'development' || p.config === 'shipping') pkg.config = p.config;if (typeof p.appId === 'string' && p.appId !== '') pkg.appId = p.appId;if (typeof p.sourceMaps === 'boolean') pkg.sourceMaps = p.sourceMaps;+ if (typeof p.minifyScripts === 'boolean') pkg.minifyScripts = p.minifyScripts;if (typeof p.frameDebugger === 'boolean') pkg.frameDebugger = p.frameDebugger;if (typeof p.openFolder === 'boolean') pkg.openFolder = p.openFolder;if (typeof p.compressWasm === 'boolean') pkg.compressWasm = p.compressWasm;diff --git a/pipeline/src/project/runtimeConfig.ts b/pipeline/src/project/runtimeConfig.tsindex 0d88d7f18..d04a9898a 100644--- a/pipeline/src/project/runtimeConfig.ts+++ b/pipeline/src/project/runtimeConfig.ts@@ -289,6 +289,7 @@ export interface PackagingOptions {engineSubpackage: boolean;excludeScenes: string[];sourcemap: boolean;+ minifyScripts: boolean;appIcon: string | undefined;/** How the page's start screen should look; see SplashPackaging. */splash: ProjectPackaging['splash'];@@ -308,6 +309,7 @@ export function packagingOptionsOf(manifest: Pick<ProjectManifest, 'packaging' |// A shipping build carries no maps unless the project asked; `config` is the// word the dialog uses for the same choice.sourcemap: p?.sourceMaps ?? (p?.config === 'development'),+ minifyScripts: p?.minifyScripts ?? true,appIcon: p?.icon,splash: p?.splash,};diff --git a/pipeline/tests/packaging-settings-reach.test.ts b/pipeline/tests/packaging-settings-reach.test.tsindex 34a23eb40..7808a8a61 100644--- a/pipeline/tests/packaging-settings-reach.test.ts+++ b/pipeline/tests/packaging-settings-reach.test.ts@@ -8,6 +8,7 @@* through the derivation the headless export spreads — the step that was missing* when `compressWasm` was honoured by the Build dialog and by nothing else.*/+import { minifiesScripts } from '../src/export/scriptMinify';import { describe, it, expect } from 'vitest';import { parseManifest } from '../src/project/format';import { packagingOptionsOf, cookOptionsOf } from '../src/project/runtimeConfig';@@ -28,6 +29,14 @@ describe('a packaging setting a project declares', () => {});});+ it('minifies scripts unless the project or a development build says not to', () => {+ expect(packagingOptionsOf(project({})).minifyScripts).toBe(true);+ expect(packagingOptionsOf(project({ minifyScripts: false })).minifyScripts).toBe(false);+ expect(minifiesScripts({ minifyScripts: true })).toBe(true);+ expect(minifiesScripts({ minifyScripts: false, minify: true })).toBe(false);+ expect(minifiesScripts({ minifyScripts: true, minify: false })).toBe(false);+ });+it('carries the asset-compression choice the cook reads', () => {expect(cookOptionsOf(project({ assetCompression: 'skip' })).compressTextures).toBe(false);expect(cookOptionsOf(project({ assetCompression: 'auto' })).compressTextures).toBe(true);diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex b0eab09c0..2068b9755 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'feat(export): scripts are minified on export unless the project turns it off':+ {"note":"An exported game's scripts are minified"},'feat(cocos): a document the creator edited moves from the layer Cocos.Widget to the engine RectAnchors on re-import':{"internal":"the Cocos importer and compatibility layer are held on the cocos-import branch and are not in this release"},'feat(ui): RectAnchors pins world content to its parent rectangle or the screen in the engine, and the Cocos Widget is a view on it':