Skip to content

Commit

Permalink
Add include/exclude options for wasm plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
sky0014 committed Aug 11, 2023
1 parent 5ec2abe commit b5a679c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,8 @@
"contributors": [
"Jamen Marz <[email protected]>",
"Colin Eberhardt <[email protected]>"
]
],
"dependencies": {
"@rollup/pluginutils": "^5.0.2"
}
}
6 changes: 6 additions & 0 deletions packages/wasm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from 'path';
import { createHash } from 'crypto';

import type { Plugin } from 'rollup';
import { createFilter } from '@rollup/pluginutils';

import type { RollupWasmOptions } from '../types';

Expand All @@ -19,6 +20,7 @@ export function wasm(options: RollupWasmOptions = {}): Plugin {

const syncFiles = sync.map((x) => path.resolve(x));
const copies = Object.create(null);
const filter = createFilter(options.include, options.exclude);

return {
name: 'wasm',
Expand All @@ -36,6 +38,10 @@ export function wasm(options: RollupWasmOptions = {}): Plugin {
return getHelpersModule(targetEnv);
}

if (!filter(id)) {
return null;
}

if (!/\.wasm$/.test(id)) {
return null;
}
Expand Down
13 changes: 13 additions & 0 deletions packages/wasm/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Plugin } from 'rollup';
import type { FilterPattern } from '@rollup/pluginutils'

/**
* - `"auto"` will determine the environment at runtime and invoke the correct methods accordingly
Expand Down Expand Up @@ -31,6 +32,18 @@ export interface RollupWasmOptions {
* Configures what code is emitted to instantiate the Wasm (both inline and separate)
*/
targetEnv?: TargetEnv;
/**
* A picomatch pattern, or array of patterns, which specifies the files in the build the plugin
* should operate on.
* By default all wasm files are targeted.
*/
include?: FilterPattern;
/**
* A picomatch pattern, or array of patterns, which specifies the files in the build the plugin
* should _ignore_.
* By default no files are ignored.
*/
exclude?: FilterPattern;
}

/**
Expand Down

0 comments on commit b5a679c

Please sign in to comment.