跳到正文
Skillpedia
通用编程6.4k · #14199

melonjs-deployment

它能做什么

它涵盖创建新的 melonJS 项目、为网页构建,以及为移动或游戏平台打包。适用于希望发布 melonJS 游戏的开发者。

适用场景

  • ✓当开发者想从官方模板开始一个新的 melonJS 游戏项目时。
  • ✓当开发者想把 melonJS 游戏打包为 iPhone 或 Android 应用时。
  • ✓当开发者想把 melonJS 游戏发布到游戏平台时。

技能链接

https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-deployment/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-deployment/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请为我创建一个新的 melonJS 游戏项目,并告诉我如何为网页构建它。”

每周 5 个新技能,1 分钟读完。

工作原理

该技能使用官方项目模板,然后说明如何构建游戏并检查浏览器支持情况,包括为旧浏览器进行转译。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Starting and shipping a project

Scaffolding

Start from the template rather than assembling a build by hand:

npm create melonjs@latest my-game

The project name is required — without it the command prints its usage and exits. It downloads the melonJS TypeScript boilerplate (Vite, TypeScript and the debug plugin already wired in), which saves you the top-level-await and asset-path issues that a hand-rolled config usually hits first.

Adding melonJS to an existing project

npm install melonjs
import { Application, Sprite, loader } from "melonjs";

The package is a tree-shakeable ES module with TypeScript declarations included and no runtime dependencies.

A CDN build exists for quick experiments, but not for production:

<script type="module">
    import { Application } from "https://cdn.jsdelivr.net/npm/melonjs@20/+esm";
</script>

Browser support and transpiling

The published bundle targets ES2022 and uses private class members. A browser that predates that cannot parse the file at all — it fails at load, not when a feature is used, so the symptom is a blank page with a syntax error.

To support older browsers, transpile melonJS together with your own code. The usual trap is that build setups skip node_modules by default, leaving melonJS untouched however low you set your target:

// vite.config.js — esbuild downlevels dependencies too
export default { build: { target: "es2020" } };
// webpack: the default `exclude: /node_modules/` would skip melonjs
{ test: /\.js$/, exclude: /node_modules\/(?!melonjs)/, use: "babel-loader" }

Two caveats worth knowing:

  • Transpiling handles syntax only. Built-in methods need separate polyfills; a bundler's target setting will never add them.
  • Downlevelled private class members become WeakMap lookups, and melonJS uses them in the renderer's hot paths. This is a real trade, not a free switch.

Native apps

Capacitor is the current recommendation for iOS and Android — see @melonjs/capacitor-plugin. Cordova also works and is documented, but is the older route.

The thing that breaks first in both is asset loading: the app is served from file://, where fetch() cannot read local files. melonJS's loader falls back to XHR for that scheme, so engine-loaded assets work — but any fetch() in your game code will fail there.

Mini-game platforms

WeChat Mini Games and Facebook Instant Games are both documented in the wiki. Note that device.platform.isWeixin detects WeChat's in-app browser, which is a normal WebView. WeChat Mini Games are a different runtime with no DOM, and need platform-specific adaptation rather than just detection — the one hook the engine offers is that the renderer adopts a globalThis.canvas when the runtime's adapter provides one, instead of creating its own.

Size

The whole engine is roughly 250 KB minzipped. Tree-shaking helps less than you might expect — the engine's subsystems reach each other, so a game importing a handful of symbols still pulls most of it. Budget for the full figure.

Practical wins are in assets, not the engine: pack sprites into atlases, prefer one tileset over several, and use stream: true for long music tracks so they are not decoded into memory.

Symptom → cause

symptom cause
blank page, syntax error in the console browser older than the ES2022 target
transpiling changes nothing build config excludes node_modules
assets 404 in a packaged native app fetch() in game code — file:// needs XHR
a built-in method is missing after transpiling transpiling is syntax-only; polyfills are separate
bundle much larger than expected tree-shaking recovers little — subsystems are interconnected

Related skills

  • melonjs — the companion packages, including the Capacitor plugin
  • melonjs-getting-started — the Application bootstrap the template produces
常见问题

这个模板包含什么?

它搭建了一个 TypeScript 项目,已预先配置好 Vite 和调试插件。

为什么我的游戏在旧浏览器上显示空白页面?

引擎的打包文件面向现代标准,因此旧浏览器可能根本无法加载它。

我能把 melonJS 添加到现有项目中吗?

可以。该技能说明应使用 npm 安装该包。

详情

作者的原始描述

Use this skill when packaging, shipping or scaffolding a melonJS game — starting a project with create-melonjs, building for the web, wrapping as a native app with Capacitor or Cordova, publishing to WeChat Mini Games or Facebook Instant Games, browser support and transpiling. Triggers on: create-melonjs, scaffold, new project, build, deploy, publish, Capacitor, Cordova, native app, iOS, Android, WeChat, Instant Games, browser support, transpile, ES2022, bundle size, tree-shaking.

repo: melonjs/melonJS

热度

GitHub 星标
6.4k
排名
#14199
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能