Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I load compiled files from a subfolder? #6164

Closed
Evolveye opened this issue Jan 31, 2018 · 6 comments
Closed

How can I load compiled files from a subfolder? #6164

Evolveye opened this issue Jan 31, 2018 · 6 comments

Comments

@Evolveye
Copy link

Evolveye commented Jan 31, 2018

How can I load compiled files from a subfolder?

I want to create a project with such file architecture:

/webassembly/
    ├ index.html
    ├ css/
    ├ js/
    └ wasm/
        ├ example.cpp
        ├ example.js (generated by emscripten)
        └ example.wasm (generated by emscripten)

I'm using that emcc command syntax:
image

I'm loading example.js file by that markup:
image

Finally, the console is showing me that error:
imageimage

I did some research, but I didn't find any way to solve that problem.
Keeping all files in the root directory isn't good idea :/

@juj
Copy link
Collaborator

juj commented Jan 31, 2018

You can define a custom function in the Module object to specify how the compiled output downloads files relative to the main .js file. In your shell file:

Module.locateFile = function(url) { return 'wasm/'+url; };

Currently the semantics are to treat relative URLs to be processed relative to the document's baseURI (the location of the .html file). There is a proposal to make relative URLs be treated relative to the .js file instead of being relative to the baseURI, but that's a semantically breaking change so has not yet proceeded; see #5484, #5368 (these relate to fixing another similar issue in node.js so the conversation ranges)

@Evolveye
Copy link
Author

Evolveye commented Jan 31, 2018

Great!

For future embarrassed people:

<script> window.Module = { locateFile: url => `./path/${url}`} </script>
<script src="./path/compiled.js"></script>

Well, i have included the script, but now console is showing me that warning:
image

I read about it, but nobody find the solution. Do You know how can I fix that?

@juj
Copy link
Collaborator

juj commented Jan 31, 2018

Check out this recent emscripten-discuss thread: https://groups.google.com/d/msg/emscripten-discuss/C7-i1gqWay4/x2sSl2qmBQAJ

@froydnj
Copy link
Contributor

froydnj commented Feb 6, 2018

@kripken or @juj, it looks like this issue has been addressed; can we close it?

@kripken
Copy link
Member

kripken commented Feb 7, 2018

Yeah, and I see we already have docs on the wiki.

@kripken kripken closed this as completed Feb 7, 2018
0b01 added a commit to 0b01/cargo-web that referenced this issue Dec 3, 2018
@chase-moskal
Copy link

@Evolveye

i attempted to use your solution, however, even though the emscripten module is picking up locateFile, i can see that locateFile is never actually being called or used

	window.Module = {
		locateFile: url => {
			console.log("LOCATE", url)
			debugger
			return `./path/${url}`
		}
	}

the emscripten module is looking for webp.wasm and webp.js.mem at the server root, which is the wrong location, and i'm trying to influence the emscripten module to look at the location relative to the emscripten module -- but emscripten appears to be ignoring my locateFile definition

i can see in the debugger that emscripten is initially picking up my Module definition here, but i don't know why it's not being called

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants