Compilar para la Web

Ver también

Esta página describe cómo compilar el editor y las plantillas de exportación para HTML5 desde el código fuente. Si estás buscando exportar tu proyecto a HTML5, lee Exportar para la Web.

Requerimientos

Para compilar las plantillas de exportación para la Web, se requiere lo siguiente:

Ver también

Para obtener el código fuente de Godot para compilarlo, consulta la sección Consiguiendo el código fuente.

Para obtener una visión general del uso de SCons para Godot, consulta la sección Introducción al sistema de compilación.

Construyendo plantillas de exportación

Antes de comenzar, asegúrate de que emcc esté disponible en tu PATH. Esto suele estar configurado por el SDK de Emscripten, por ejemplo, al invocar emsdk activate y 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

GDExtensión

Las plantillas de exportación predeterminadas no son compatibles con GDExtension por motivos de rendimiento y compatibilidad. Consulta export page para obtener más información.

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

Building the editor

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.

Consulta la (página de exportación) para obtener los requisitos del servidor web en la sección de exportación para web.

Truco

El repositorio Godot incluye un script de Python para alojar un servidor web local. Esto se puede utilizar para probar el editor web localmente.

Después de compilar el editor, extraiga el archivo ZIP que se creó en la carpeta bin/, luego ejecute el siguiente comando en la raíz del repositorio 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.

Note that for production use cases, this Python-based web server should not be used. Instead, you should use an established web server such as Apache or nginx.