'build' path isn't taken into account
badescuga opened this issue · comments
Although i pass the build path to the loader, it doesn't take it into account. Thus, my .wasm file ends up in the root of the project.
{
test: /\.(c|cpp)$/,
use: {
loader: 'cpp-wasm-loader',
options: {
// Path to your 'build' or 'dist' directory relative to project root
buildPath: 'build',
// emccPath: './emsdk',
// emccFlags: ['-O3']
}
}
}
This parameter actually meant something different, but it was obsolete and wasn't used. What do you want to achieve? When you build your project with webpack, you want to store the .wasm files in a folder, for example dist/wasm/*.wasm
?
yeah, i want as you describe @Kobzol -- i have my webpack setup with a publicPath: /__build__/
, so I need https://github.com/Kobzol/cpp-wasm-loader/blob/7fcdb4393fab2aeeacecdf1ed55ad564b0e75754/src/index.js#L19 to essentially become wasmBinaryFile: '/__build__/' + wasmName
-- is there a way to achieve that, especially w/o explicitly re-specifying the publicPath
for this loader? I've never dug into the guts of a webpack loader before, but can the loader access the "globally" configured publicPath?
looks like maybe __webpack_public_path__
could be used
guess not. tried it, got "ReferenceError: webpack_public_path is not defined". still investigating.
ah, maybe the problem isn't to set that wasmBinaryFile
as i thought. it seems the compiled js from emcc
contains var wasmBinaryFile = 'filename-without-publicPath.wasm';
. so perhaps there's a flag that can be passed to emcc
to resolve this...
aha! i think the key lies in injection the option locateFile
into the Module of https://github.com/Kobzol/cpp-wasm-loader/blob/7fcdb4393fab2aeeacecdf1ed55ad564b0e75754/src/index.js#L18-L21
ref: https://kripken.github.io/emscripten-site/docs/api_reference/module.html#Module.locateFile
that's the idea, anyway, but actually that Module gets stringified later, so we can't just stick a function there (cuz functions get lost in JSON.stringify), we'd have to stick it in the template string that follows. no big deal. but the last missing piece is I still haven't figured out how to get the publicPath
from inside the loader.
Closing this issue since it's been resolved with PR.