Custom HTML templates and WebAssembly


#1

Hi all!

If you are currently using a custom HTML template for your HTML5 bundling (specified as html5.htmlfile in your game.project) you might have problems after the latest update (1.2.141).

This is due to us changing the name of the engine binaries in HTML5 bundles. Previously there was only one engine JavaScript file (<project_name>.js), but after 1.2.141 there is actually two files (<project_name>_asmjs.js for AsmJS and <project_name>_wasm.js for WebAssembly).

The quickest fix is to bundle your project once without a custom HTML template and compare the output with your custom one to see what needs to be updated. But in short what you need to do is;

  • Remove the following line, ;
<script type='text/javascript' src="{{DEFOLD_ENGINE}}" async onload="{{DEFOLD_DEV_INIT}}"></script>
  • And add the following lines inside the <script> block, just after Module['onRuntimeInitialized'] {...};
	Module["locateFile"] = function(path, scriptDirectory)
	{
		// dmengine*.wasm is hardcoded in the built JS loader for WASM,
		// we need to replace it here with the correct project name.
		if (path == "dmengine.wasm" || path == "dmengine_release.wasm" || path == "dmengine_headless.wasm") {
			path = "{{DEFOLD_BINARY_PREFIX}}.wasm";
		}
		return scriptDirectory + path;
	};
 	var engineJS = document.createElement('script');
	engineJS.type = 'text/javascript';
	if (Module['isWASMSupported']) {
	    engineJS.src = '{{DEFOLD_BINARY_PREFIX}}_wasm.js';
	} else {
	    engineJS.src = '{{DEFOLD_BINARY_PREFIX}}_asm.js';
	}
	document.head.appendChild(engineJS);

If you encounter any issues, please reply here and we will try to help!


We are also moving the packaged/default HTML template into the builtins folder (just as we did with Info.plist and AndroidManifest.xml) so it will be easier to view and keep track of. This change will hopefully be available already in the next release (1.2.142). :slight_smile:


Defold 1.2.141 has been released
#2

#3

This is now resolved in 1.2.142, the HTML template has been moved into the builtins/manifests/web/ folder.