Skip to content

Commit

Permalink
Fix import.meta error (#340)
Browse files Browse the repository at this point in the history
* Fix import.meta error

Update our workaround for webpack not supporting import.meta properly,
which causes an error when trying to use the Wasm web bindings with some
frameworks, e.g. React.

* Improve workaround regex
  • Loading branch information
cycraig authored Jul 28, 2021
1 parent bfb139f commit 9d544f3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bindings/wasm/build/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const fs = require('fs')

const entryFilePath = path.join(__dirname, '../web/identity_wasm.js')
const entryFile = fs.readFileSync(entryFilePath).toString()
// comment out this code so it works for Webpack
let changedFile = entryFile.replace(
"input = import.meta.url.replace(",
"// input = import.meta.url.replace("
)
let changedFile = entryFile
// Comment out generated code as a workaround for webpack (does not recognise import.meta)
// Regex to avoid hard-coding 'identity_wasm_bg.wasm'
.replace(
/input = new URL\((.*), import\.meta\.url\);/i,
"// input = new URL($1, import.meta.url);"
)
// Rename original init function, because we want to use the name for our own function
.replace(
"async function init(input) {",
Expand Down

0 comments on commit 9d544f3

Please sign in to comment.