diff --git a/packages/wasm/package.json b/packages/wasm/package.json index 9ecd8a831..8a9a9fea2 100644 --- a/packages/wasm/package.json +++ b/packages/wasm/package.json @@ -82,5 +82,8 @@ "contributors": [ "Jamen Marz ", "Colin Eberhardt " - ] + ], + "dependencies": { + "@rollup/pluginutils": "^5.0.2" + } } diff --git a/packages/wasm/src/index.ts b/packages/wasm/src/index.ts index 6607caa12..36c93cd3c 100644 --- a/packages/wasm/src/index.ts +++ b/packages/wasm/src/index.ts @@ -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'; @@ -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', @@ -36,6 +38,10 @@ export function wasm(options: RollupWasmOptions = {}): Plugin { return getHelpersModule(targetEnv); } + if (!filter(id)) { + return null; + } + if (!/\.wasm$/.test(id)) { return null; } diff --git a/packages/wasm/types/index.d.ts b/packages/wasm/types/index.d.ts index 62921467f..8f1d4d849 100644 --- a/packages/wasm/types/index.d.ts +++ b/packages/wasm/types/index.d.ts @@ -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 @@ -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; } /**