Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
为 Web 平台编译
参见
本页面描述的是如何从源码编译 HTML5 编辑器和导出模板二进制文件。如果你想要将项目导出到 HTML5,请移步《为 Web 导出》。
需求
编译 Web 的导出模板需要以下内容:
SCons 4.0+ build system.
构建导出模板
在开始之前,确认 emcc
在你的 PATH 中是可用的。这通常是由 Emscripten SDK 配置的,例如在调用 emsdk activate
和 source ./emsdk_env.sh
/emsdk_env.bat
时。
打开终端并导航到引擎源代码的根目录。然后指示 SCons 构建 JavaScript 平台。将 target
指定 release
以用于发布版本,或将 target
指定 release_debug
以用于调试版本:
scons platform=web target=template_release
scons platform=web target=template_debug
默认情况下,JavaScriptBridge 单例 将被内置到引擎中。官方导出模板也启用了 JavaScript 单例。由于 eval()
调用可能存在安全隐患,因此可以使用 javascript_eval
选项,以在不使用单例的情况下进行构建:
scons platform=web target=template_release javascript_eval=no
scons platform=web target=template_debug javascript_eval=no
By default, WebWorker threads support is enabled. To disable it and only use a single thread,
the threads
option can be used to build the web template without threads support:
scons platform=web target=template_release threads=no
scons platform=web target=template_debug threads=no
现在,引擎将由 Emscripten 编译为 WebAssembly。完成后,生成的文件将放在 bin
子目录中。其名称针对发布版本是 godot.web.template_release.wasm32.zip
,或针对调试版本是 godot.web.template_debug.wasm32.zip
。
最后将 zip 归档文件重命名为 web_release.zip
,作为发布模板:
mv bin/godot.web.template_release.wasm32.zip bin/web_release.zip
调试模板则重命名为 web_debug.zip
:
mv bin/godot.web.template_debug.wasm32.zip bin/web_debug.zip
GDExtension
The default export templates do not include GDExtension support for performance and compatibility reasons. See the export page for more info.
You can build the export templates using the option dlink_enabled=yes
to enable GDExtension support:
scons platform=web dlink_enabled=yes target=template_release
scons platform=web dlink_enabled=yes target=template_debug
Once finished, the resulting file will be placed in the bin
subdirectory.
Its name will have _dlink
added.
最后将 zip 归档文件重命名为 web_dlink_release.zip
和 web_dlink_release.zip
,作为发布模板:
mv bin/godot.web.template_release.wasm32.dlink.zip bin/web_dlink_release.zip
mv bin/godot.web.template_debug.wasm32.dlink.zip bin/web_dlink_debug.zip
构建编辑器
It is also possible to build a version of the Godot editor that can run in the browser. The editor version is not recommended over the native build. You can build the editor with:
scons platform=web target=editor
Once finished, the resulting file will be placed in the bin
subdirectory.
Its name will be godot.web.editor.wasm32.zip
. You can upload the
zip content to your web server and visit it with your browser to use the editor.
Refer to the export page for the web server requirements.
小技巧
Godot 仓库包含一个 Python 脚本,用于托管本地 web 服务器。这可以用来在本地测试 Web 编辑器。
编译完编辑器后,解压在 bin/
文件夹中创建的 ZIP 文件,然后在 Godot 仓库根目录中运行以下命令:
# You may need to replace `python` with `python3` on some platforms.
python platform/web/serve.py
This will serve the contents of the bin/
folder and open the default web
browser automatically. In the page that opens, access godot.editor.html
and you should be able to test the web editor this way.
请注意,对于生产用例,不应使用此基于 Python 的 Web 服务器。相反,你应该使用已建立的 Web 服务器,例如 Apache 或 nginx。