Skip to content

Commit 7bee6a8

Browse files
authored
Fixing require to be ignored by Webpack (#2115)
* Fixing require to be ignored by Webpack * Making the module.require even more dynamic, to trick Webpack
1 parent 6d61cd8 commit 7bee6a8

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

crates/cli-support/src/js/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ impl<'a> Context<'a> {
12511251
self.global(&format!(
12521252
"
12531253
const l{0} = typeof {0} === 'undefined' ? \
1254-
require('util').{0} : {0};\
1254+
(0, module.require)('util').{0} : {0};\
12551255
",
12561256
s
12571257
));

crates/cli/tests/reference/anyref-import-catch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as wasm from './reference_test_bg.wasm';
22

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

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

crates/cli/tests/reference/string-arg.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as wasm from './reference_test_bg.wasm';
22

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

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

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

2121
let WASM_VECTOR_LEN = 0;
2222

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

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

0 commit comments

Comments
 (0)