From b5a679cc58d5ed542566e76c0c7da29eae0e3e4e Mon Sep 17 00:00:00 2001 From: sky0014 Date: Fri, 11 Aug 2023 20:50:57 +0800 Subject: [PATCH] Add include/exclude options for wasm plugin. --- packages/wasm/package.json | 5 ++++- packages/wasm/src/index.ts | 6 ++++++ packages/wasm/types/index.d.ts | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) 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; } /**