Skip to content

Commit

Permalink
Merge pull request #55 from mysterycommand/fix/handle-import-meta-url
Browse files Browse the repository at this point in the history
Handle import.meta.url
  • Loading branch information
mysterycommand authored Jun 27, 2019
2 parents 7b21fb5 + a349e50 commit 8b1ad00
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/WasmPackAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@ class WasmPackAsset extends Asset {
const exportNames = Array.from(
matches(/export (?:class|const|function) (\w+)/g, initStr),
).map(([_, name]) => name);
const init = initStr.replace(
'return wasm;',
`return { ${exportNames.join(', ')} };`,
);
const init = initStr
.replace('return wasm;', `return { ${exportNames.join(', ')} };`)
.replace(
`module = import.meta.url.replace(/\.js$/, '_bg.wasm');`,
`throw new Error('the \`module\` argument is required for use with \`parcel-plugin-wasm-pack\`');`,
);
await fs.writeFile(initPath, init);

await this.addDependency(path.relative(dir, wasmPath));
Expand Down

0 comments on commit 8b1ad00

Please sign in to comment.