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 3.1.2+ build system.
备注
Emscripten 3.1.39+ is recommended, but older 3.x versions are known to work.
Please note that the minimum requirement for GDExtension support is 3.1.14.
构建导出模板¶
在开始之前,确认 emcc 在你的 PATH 中是可用的。这通常是由 Emscripten SDK 配置的,例如在调用 emsdk activate 和 source ./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
By default, the JavaScriptBridge singleton will be built
into the engine. Official export templates also have the JavaScript singleton
enabled. Since eval() calls can be a security concern, the
javascript_eval option can be used to build without the singleton:
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
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.template_release.wasm32.zip for release or godot.web.template_debug.wasm32.zip
for debug.
Finally, rename the zip archive to web_release.zip for the
release template:
mv bin/godot.web.template_release.wasm32.zip bin/web_release.zip
And web_debug.zip for the debug template:
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.
Finally, rename the zip archives to web_dlink_release.zip and
web_dlink_release.zip for the release template:
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.
关于网络服务器的要求,请参考导出页面。
小技巧
Godot 仓库包含一个 `Python 脚本,用于托管本地 web 服务器 < https://raw.githubusercontent.com/godotengine/Godot/master/platform/web/serve.py >`__ 。这可以用来在本地测试 Web 编辑器。
编译完编辑器后,解压在 bin/ 文件夹中创建的 ZIP 文件,然后在 Godot 仓库根目录中运行以下命令:
# You may need to replace `python` with `python3` on some platforms.
python platform/web/serve.py
这将为 bin/ 文件夹中的内容运行网页服务,并自动打开默认的浏览器。在打开的页面中访问 godot.tools.html ,你可以使用这种方式测试 Web 编辑器。
请注意,对于生产用例,不应使用此基于Python的Web服务器。相反,你应该使用已建立的Web服务器,例如Apache或nginx。