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...
Kompilieren für das Web
Siehe auch
Diese Seite beschreibt, wie man HTML5-Editor und Exportvorlagen-Binärdateien aus den Quellen kompiliert. Wenn Sie Ihr Projekt stattdessen nach HTML5 exportieren möchten, lesen Sie Exportieren für das Web.
Anforderungen
Zum Kompilieren von Exportvorlagen für das Web ist Folgendes erforderlich:
SCons 4.4+ build system.
Siehe auch
Um den Godot-Quellcode zum Kompilieren zu erhalten, siehe Beschaffung des Quellcodes.
Eine allgemeine Übersicht über die Verwendung von SCons für Godot finden Sie unter Einführung in das Buildsystem.
Exportvorlagen erstellen
Bevor Sie beginnen, stellen Sie sicher, dass emcc in Ihrem PATH verfügbar ist. Dies wird normalerweise durch das Emscripten-SDK konfiguriert, z.B. beim Aufruf von emsdk activate und 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
Die Engine wird nun von Emscripten in WebAssembly kompiliert. Sobald die Kompilierung abgeschlossen ist, wird die resultierende Datei im Unterverzeichnis bin abgelegt. Ihr Name ist godot.web.template_release.wasm32.zip für Release oder godot.web.template_debug.wasm32.zip für 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
Die Default-Exportvorlagen enthalten aus Performance- und Kompatibilitätsgründen keine GDExtension-Unterstützung. Siehe die Export-Seite für weitere Informationen.
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
Wenn Sie fertig sind, wird die resultierende Datei in das Unterverzeichnis bin gelegt. Ihr Name wird mit _dlink ergänzt.
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
Bauen des Editors
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
Sobald Sie fertig sind, wird die resultierende Datei im Unterverzeichnis bin abgelegt. Ihr Name ist godot.web.editor.wasm32.zip. Sie können den Zip-Inhalt auf Ihren Webserver hochladen und ihn mit Ihrem Browser besuchen, um den Editor zu benutzen.
Siehe die Export-Seite für die Anforderungen an den Webserver.
Tipp
Das Godot-Repository enthält ein Python-Skript zum Hosten eines lokalen Webservers. Dieser kann verwendet werden, um den Webeditor lokal zu testen.
Nachdem Sie den Editor kompiliert haben, entpacken Sie das ZIP-Archiv, das im Ordner bin/ erstellt wurde, und führen dann den folgenden Befehl im Godot-Repository-Stammverzeichnis aus:
# 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.
Beachten Sie, dass dieser auf Python basierende Webserver nicht für Produktionszwecke verwendet werden sollte. Stattdessen sollten Sie einen etablierten Webserver wie Apache oder nginx verwenden.