File tree 1 file changed +15
-5
lines changed
packages/vite/src/node/plugins
1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -7,11 +7,21 @@ const wasmHelperId = '/__vite-wasm-helper'
7
7
const wasmHelper = async ( opts = { } , url : string ) => {
8
8
let result
9
9
if ( url . startsWith ( 'data:' ) ) {
10
- // @ts -ignore
11
- const binaryString = atob ( url . replace ( / ^ d a t a : .* ?b a s e 6 4 , / , '' ) )
12
- const bytes = new Uint8Array ( binaryString . length )
13
- for ( let i = 0 ; i < binaryString . length ; i ++ ) {
14
- bytes [ i ] = binaryString . charCodeAt ( i )
10
+ const urlContent = url . replace ( / ^ d a t a : .* ?b a s e 6 4 , / , '' )
11
+ let bytes
12
+ if ( typeof Buffer === 'function' && typeof Buffer . from === 'function' ) {
13
+ bytes = Buffer . from ( urlContent , 'base64' )
14
+ } else if ( typeof atob === 'function' ) {
15
+ // @ts -ignore
16
+ const binaryString = atob ( urlContent )
17
+ bytes = new Uint8Array ( binaryString . length )
18
+ for ( let i = 0 ; i < binaryString . length ; i ++ ) {
19
+ bytes [ i ] = binaryString . charCodeAt ( i )
20
+ }
21
+ } else {
22
+ throw new Error (
23
+ 'Failed to decode base64-encoded data URL, Buffer and atob are not supported'
24
+ )
15
25
}
16
26
// @ts -ignore
17
27
result = await WebAssembly . instantiate ( bytes , opts )
You can’t perform that action at this time.
0 commit comments