简体   繁体   中英

Emscripten - How to override locateFile when compiled with MODULARIZE options

I have some files added to the virtual file system using --preload-file

I try to change the data file location using:

MyModule['locateFile'] = function(path, prefix) {
  if (path.endsWith(".data")) return "resources/" + path
  return prefix + path
}

But if I add -s MODULARIZE=1 -s 'EXPORT_NAME="MyModule"' , it doesn't work.

I try to add the locateFile function in a dedicated script as explained here .

I also tried using pre-js and extern-pre-js options but that doesn't work either

I finally found the solution by reading the FAQ and the settings.js file, in particular:

The factory function accepts 1 parameter, an object with default values for the module instance:

const module = await EXPORT_NAME({ option: value, ... });

So we can pass the function like this:

function locateFile(path, prefix) {
  if (path.endsWith(".data")) return "resources/" + path
  return prefix + path
}

MyModule({'locateFile' : locateFile}).then(...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM