Skip to content

Commit

Permalink
fix(warning): add buffer as external dependency
Browse files Browse the repository at this point in the history
this will dismiss warning:
```console
'buffer' is imported but could not be resolved – treating it as an external dependency
```
  • Loading branch information
DrSensor committed Aug 25, 2018
1 parent 8717c44 commit 9b9a093
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main.js
Expand Up @@ -19,6 +19,17 @@ export default function(options: $Shape<Options> = {}) {

return {
name: 'rust',
options(opts: any) {
let external: string[] | ((id: string) => boolean);

if (typeof opts.external === 'function')
external = id => opts.external(id) || id.includes('buffer');

if (Array.isArray(opts.external))
external = Array.from(new Set(opts.external.concat('buffer')));

return Object.assign({}, opts, { external });
},
async transform(code: string, id: string) {
if (!extension.test(id)) return;
if (!filter(id)) return;
Expand All @@ -39,7 +50,7 @@ export default function(options: $Shape<Options> = {}) {
return wrap(wasmCode).asWebAssembly.Instance;
case 'module':
return wrap(wasmCode).asWebAssembly.Module;
case 'promise' || 'async':
case 'async':
return wrap(wasmCode).promiseWebAssembly.Both;
case 'async-instance':
return wrap(wasmCode).promiseWebAssembly.Instance;
Expand Down

0 comments on commit 9b9a093

Please sign in to comment.