Skip to content

Commit 6795fdd

Browse files
lbogdanCompuIves
authored andcommitted
Make raw-loader load the contents of binary modules (codesandbox#770)
1 parent 17fd487 commit 6795fdd

File tree

1 file changed

+12
-5
lines changed
  • packages/app/src/sandbox/eval/transpilers/raw

1 file changed

+12
-5
lines changed

packages/app/src/sandbox/eval/transpilers/raw/index.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ class RawTranspiler extends Transpiler {
66
super('raw-loader');
77
}
88

9-
doTranspilation(code: string) {
10-
return Promise.resolve({
11-
transpiledCode: `
12-
module.exports = ${JSON.stringify(code)};`,
13-
});
9+
async doTranspilation(code: string) {
10+
// code is a URL, this is probably a binary module, load its contents
11+
if (code.substr(0, 4) === 'http') {
12+
const res = await fetch(code);
13+
const text = await res.text();
14+
return {
15+
transpiledCode: `module.exports = ${JSON.stringify(text)};`,
16+
};
17+
}
18+
return {
19+
transpiledCode: `module.exports = ${JSON.stringify(code)};`,
20+
};
1421
}
1522
}
1623

0 commit comments

Comments
 (0)