You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: site/source/docs/api_reference/module.rst
+14-2
Original file line number
Diff line number
Diff line change
@@ -53,13 +53,25 @@ The following ``Module`` attributes affect code execution. Set them to customize
53
53
54
54
.. js:attribute::Module.locateFile
55
55
56
-
If set, this method will be called when the runtime needs to load a file, such as a ``.wasm`` WebAssembly file, ``.mem`` memory init file, or a file generated by the file packager. The function receives the relative path to the file as configured in build process and a ``prefix`` (path to JavaScript file), and should return the actual URL. This lets you host file packages or the ``.mem`` file etc. on a different location than the directory of JavaScript file (which is the default expectation), for example if you want to host them on a CDN. NOTE: ``prefix`` might be empty string for memory initializer file is loaded in parallel with JS or in packager, so be careful with those.
56
+
If set, this method will be called when the runtime needs to load a file, such as a ``.wasm`` WebAssembly file, ``.mem`` memory init file, or a file generated by the file packager. The function receives the relative path to the file as configured in build process and a ``prefix`` (path to the main JavaScript file's directory), and should return the actual URL. This lets you host file packages or the ``.mem`` file etc. on a different location than the directory of the JavaScript file (which is the default expectation), for example if you want to host them on a CDN.
57
+
58
+
.. note:: ``prefix`` might be an empty string, if ``locateFile`` is called before we load the main JavaScript. For example, that can happen if a file package or a mememory initializer file are loaded beforehand (perhaps from the HTML, before it loads the main JavaScript).
59
+
60
+
.. note:: Several ``Module.*PrefixURL`` options have been deprecated in favor of ``locateFile``, which includes ``memoryInitializerPrefixURL``, ``pthreadMainPrefixURL``, ``cdInitializerPrefixURL``, ``filePackagePrefixURL``. To update your code, for example if you used ``Module.memoryInitializerPrefixURL`` equal to ``"https://mycdn.com/memory-init-dir/"``, then you can replace that with something like
61
+
62
+
::
63
+
64
+
Module['locateFile'] = function(path, prefix) {
65
+
// if it's a mem init file, use a custom dir
66
+
if (path.endsWith(".mem")) return "https://mycdn.com/memory-init-dir/" + path;
67
+
// otherwise, use the default, the prefix (JS file's dir) + the path
68
+
return prefix + path;
69
+
}
57
70
58
71
.. js:attribute::Module.logReadFiles
59
72
60
73
If set, stderr will log when any file is read.
61
74
62
-
63
75
.. js:attribute::Module.onAbort
64
76
65
77
If set, this function is called when abnormal program termination occurs. That can happen due to the C method ``abort()`` being called directly, or called from JavaScript, or due to a fatal problem such as being unable to fetch a necessary file during startup (like the wasm binary when running wasm), etc. After calling this function, program termination occurs (i.e., you can't use this to try to do something else instead of stopping; there is no possibility of recovering here).
# Tests that Emscripten-compiled applications can be run from a relative path with node command line that is different than the current working directory.
0 commit comments