Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

为 Web 平台编译

参见

这个页面描述的是如何从源码编译 HTML5 编辑器和导出模板二进制文件。如果你要找的是导出项目到 HTML5,请阅读 为 Web 导出

需求

编译 Web 的导出模板需要以下内容:

参见

要获取编译所需的 Godot 源码,请参阅 获取源代码

有关 Godot 的 SCons 用法的一般概述,请参阅 构建系统介绍

构建导出模板

在开始之前,确认 emcc 在你的 PATH 中是可用的。这通常是由 Emscripten SDK 配置的,例如在调用 emsdk activatesource ./emsdk_env.sh/emsdk_env.bat 时。

Open a terminal and navigate to the root directory of the engine source code. Then instruct SCons to build the Web platform. Specify target as either template_release for a release build or template_debug for a debug build:

scons platform=web target=template_release
scons platform=web target=template_debug

默认情况下,JavaScript singleton 将被内置到引擎中,官方导出模板也启用了 JavaScript 单例。由于 eval() 调用可能是一个安全问题,javascript_eval 选项可以用来构建,而无需单例:

scons platform=web target=template_release javascript_eval=no
scons platform=web target=template_debug javascript_eval=no

The engine will now be compiled to WebAssembly by Emscripten. Once finished, the resulting file will be placed in the bin subdirectory. Its name is godot.web.opt.wasm32.zip for release or godot.web.opt.debug.wasm32.zip for debug.

Finally, rename the zip archive to web_release.zip for the release template:

mv bin/godot.web.opt.