compiling_for_web.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. .. _doc_compiling_for_web:
  2. Compiling for the Web
  3. =====================
  4. .. seealso::
  5. This page describes how to compile HTML5 editor and export template binaries from source.
  6. If you're looking to export your project to HTML5 instead, read :ref:`doc_exporting_for_web`.
  7. .. highlight:: shell
  8. Requirements
  9. ------------
  10. To compile export templates for the Web, the following is required:
  11. - `Emscripten 3.1.39+ <https://emscripten.org>`__.
  12. - `Python 3.6+ <https://www.python.org/>`__.
  13. - `SCons 3.1.2+ <https://scons.org/pages/download.html>`__ build system.
  14. .. seealso:: To get the Godot source code for compiling, see
  15. :ref:`doc_getting_source`.
  16. For a general overview of SCons usage for Godot, see
  17. :ref:`doc_introduction_to_the_buildsystem`.
  18. .. note:: Emscripten 3.1.39+ is recommended, but older 3.x versions are known to work.
  19. Please note that the minimum requirement for GDExtension support is 3.1.14.
  20. Building export templates
  21. -------------------------
  22. Before starting, confirm that ``emcc`` is available in your PATH. This is
  23. usually configured by the Emscripten SDK, e.g. when invoking ``emsdk activate``
  24. and ``source ./emsdk_env.sh``/``emsdk_env.bat``.
  25. Open a terminal and navigate to the root directory of the engine source code.
  26. Then instruct SCons to build the Web platform. Specify ``target`` as
  27. either ``template_release`` for a release build or ``template_debug`` for a debug build::
  28. scons platform=web target=template_release
  29. scons platform=web target=template_debug
  30. By default, the :ref:`JavaScriptBridge singleton <doc_web_javascript_bridge>` will be built
  31. into the engine. Official export templates also have the JavaScript singleton
  32. enabled. Since ``eval()`` calls can be a security concern, the
  33. ``javascript_eval`` option can be used to build without the singleton::
  34. scons platform=web target=template_release javascript_eval=no
  35. scons platform=web target=template_debug javascript_eval=no
  36. By default, WebWorker threads support is enabled. To disable it and only use a single thread,
  37. the ``threads`` option can be used to build the web template without threads support::
  38. scons platform=web target=template_release threads=no
  39. scons platform=web target=template_debug threads=no
  40. The engine will now be compiled to WebAssembly by Emscripten. Once finished,
  41. the resulting file will be placed in the ``bin`` subdirectory. Its name is
  42. ``godot.web.template_release.wasm32.zip`` for release or ``godot.web.template_debug.wasm32.zip``
  43. for debug.
  44. Finally, rename the zip archive to ``web_release.zip`` for the
  45. release template::
  46. mv bin/godot.web.template_release.wasm32.zip bin/web_release.zip
  47. And ``web_debug.zip`` for the debug template::
  48. mv bin/godot.web.template_debug.wasm32.zip bin/web_debug.zip
  49. GDExtension
  50. -----------
  51. The default export templates do not include GDExtension support for
  52. performance and compatibility reasons. See the
  53. :ref:`export page <doc_javascript_export_options>` for more info.
  54. You can build the export templates using the option ``dlink_enabled=yes``
  55. to enable GDExtension support::
  56. scons platform=web dlink_enabled=yes target=template_release
  57. scons platform=web dlink_enabled=yes target=template_debug
  58. Once finished, the resulting file will be placed in the ``bin`` subdirectory.
  59. Its name will have ``_dlink`` added.
  60. Finally, rename the zip archives to ``web_dlink_release.zip`` and
  61. ``web_dlink_release.zip`` for the release template::
  62. mv bin/godot.web.template_release.wasm32.dlink.zip bin/web_dlink_release.zip
  63. mv bin/godot.web.template_debug.wasm32.dlink.zip bin/web_dlink_debug.zip
  64. Building the editor
  65. -------------------
  66. It is also possible to build a version of the Godot editor that can run in the
  67. browser. The editor version is not recommended
  68. over the native build. You can build the editor with::
  69. scons platform=web target=editor
  70. Once finished, the resulting file will be placed in the ``bin`` subdirectory.
  71. Its name will be ``godot.web.editor.wasm32.zip``. You can upload the
  72. zip content to your web server and visit it with your browser to use the editor.
  73. Refer to the :ref:`export page <doc_javascript_export_options>` for the web
  74. server requirements.
  75. .. tip::
  76. The Godot repository includes a
  77. `Python script to host a local web server <https://raw.githubusercontent.com/godotengine/godot/master/platform/web/serve.py>`__.
  78. This can be used to test the web editor locally.
  79. After compiling the editor, extract the ZIP archive that was created in the
  80. ``bin/`` folder, then run the following command in the Godot repository
  81. root:
  82. ::
  83. # You may need to replace `python` with `python3` on some platforms.
  84. python platform/web/serve.py
  85. This will serve the contents of the ``bin/`` folder and open the default web
  86. browser automatically. In the page that opens, access ``godot.editor.html``
  87. and you should be able to test the web editor this way.
  88. Note that for production use cases, this Python-based web server should not
  89. be used. Instead, you should use an established web server such as Apache or
  90. nginx.