為網頁平台進行編譯¶
也參考
This page describes how to compile HTML5 editor and export template binaries from source. If you're looking to export your project to HTML5 instead, read 為 Web 匯出.
系統需求¶
要為網頁平台進行編譯,需滿足下列需求:
SCons 3.0+ 建置系統。
建置匯出樣板¶
Before starting, confirm that emcc
is available in your PATH. This is
usually configured by the Emscripten SDK, e.g. when invoking emsdk activate
and source ./emsdk_env.sh
/emsdk_env.bat
.
開啟終端機,並移至 Godot 原始碼的根目錄。接著使用 SCons 來為 JavaScript 平台建置。將如果要建置正式版本,請將 target
指定為 release
,若要建置除錯版本,請將 target
指定為 release_debug
:
scons platform=javascript tools=no target=release
scons platform=javascript tools=no target=release_debug
預設情況下, JavaScript 單例 會被建置至引擎內。官方的匯出樣板中也有開啟 JavaScript 單例。由於 eval
呼叫有安全性疑慮,因此可以通過 javascript_eval
選項來建置不包含該單例的版本:
scons platform=javascript tools=no target=release javascript_eval=no
scons platform=javascript tools=no target=release_debug javascript_eval=no
引擎會通過 Emscripten 來編譯至 WebAssembly。完成之後,產生的檔案會被放在 bin
子資料夾中。正式版本 (release) 的檔案名稱為 godot.javascript.opt.zip
,除錯版本 (debug) 為 godot.javascript.opt.debug.zip
。
最後,將用於正式樣板 (release) 的 ZIP 檔重新命名為 webassembly_release.zip
:
mv bin/godot.javascript.opt.zip bin/webassembly_release.zip
並將用於除錯樣板 (debug) 的 ZIP 檔重新命名為 webassembly_release.zip
:
mv bin/godot.javascript.opt.debug.zip bin/webassembly_debug.zip
Threads and GDNative¶
The default export templates do not include threads and GDNative support for performance and compatibility reasons. See the export page for more info.
You can build the export templates using the option threads_enabled=yes
or
gdnative_enabled=yes
to enable threads or GDNative support:
scons platform=javascript tools=no threads_enabled=yes target=release
scons platform=javascript tools=no threads_enabled=yes target=release_debug
scons platform=javascript tools=no gdnative_enabled=yes target=release
scons platform=javascript tools=no gdnative_enabled=yes target=release_debug
Once finished, the resulting file will be placed in the bin
subdirectory.
Its name will have either the .threads
or .gdnative
suffix.
Finally, rename the zip archives to webassembly_release_threads.zip
and
webassembly_release_gdnative.zip
for the release template:
mv bin/godot.javascript.opt.threads.zip bin/webassembly_threads_release.zip
mv bin/godot.javascript.opt.gdnative.zip bin/webassembly_gdnative_release.zip
And webassembly_debug_threads.zip
and webassembly_debug_gdnative.zip
for
the debug template:
mv bin/godot.javascript.opt.debug.threads.zip bin/webassembly_threads_debug.zip
mv bin/godot.javascript.opt.debug.gdnative.zip bin/webassembly_gdnative_debug.zip
Building the Editor¶
It is also possible to build a version of the Godot editor that can run in the browser. The editor version requires threads support and is not recommended over the native build. You can build the editor with:
scons platform=javascript tools=yes threads_enabled=yes target=release_debug
Once finished, the resulting file will be placed in the bin
subdirectory.
Its name will be godot.javascript.opt.tools.threads.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.