Skip to content

Commit

Permalink
Fixing require to be ignored by Webpack (#2115)
Browse files Browse the repository at this point in the history
* Fixing require to be ignored by Webpack

* Making the module.require even more dynamic, to trick Webpack
  • Loading branch information
Pauan authored Apr 29, 2020
1 parent 6d61cd8 commit 7bee6a8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ impl<'a> Context<'a> {
self.global(&format!(
"
const l{0} = typeof {0} === 'undefined' ? \
require('util').{0} : {0};\
(0, module.require)('util').{0} : {0};\
",
s
));
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/reference/anyref-import-catch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as wasm from './reference_test_bg.wasm';

const lTextDecoder = typeof TextDecoder === 'undefined' ? require('util').TextDecoder : TextDecoder;
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });

Expand Down
4 changes: 2 additions & 2 deletions crates/cli/tests/reference/string-arg.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as wasm from './reference_test_bg.wasm';

const lTextDecoder = typeof TextDecoder === 'undefined' ? require('util').TextDecoder : TextDecoder;
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });

Expand All @@ -20,7 +20,7 @@ function getStringFromWasm0(ptr, len) {

let WASM_VECTOR_LEN = 0;

const lTextEncoder = typeof TextEncoder === 'undefined' ? require('util').TextEncoder : TextEncoder;
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;

let cachedTextEncoder = new lTextEncoder('utf-8');

Expand Down

0 comments on commit 7bee6a8

Please sign in to comment.