diff --git a/packages/wasm/README.md b/packages/wasm/README.md
index c3d974529..7c38fbfa4 100755
--- a/packages/wasm/README.md
+++ b/packages/wasm/README.md
@@ -46,6 +46,20 @@ Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#comma
## Options
+### `exclude`
+
+Type: `String` | `Array[...String]`
+Default: `null`
+
+A [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. By default no files are ignored.
+
+### `include`
+
+Type: `String` | `Array[...String]`
+Default: `null`
+
+A [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should operate on. By default all wasm files are targeted.
+
### `sync`
Type: `Array[...String]`
diff --git a/packages/wasm/package.json b/packages/wasm/package.json
index 9ecd8a831..cb3655148 100644
--- a/packages/wasm/package.json
+++ b/packages/wasm/package.json
@@ -62,6 +62,9 @@
"optional": true
}
},
+ "dependencies": {
+ "@rollup/pluginutils": "^5.0.2"
+ },
"devDependencies": {
"@rollup/plugin-typescript": "^9.0.1",
"del-cli": "^5.0.0",
diff --git a/packages/wasm/src/index.ts b/packages/wasm/src/index.ts
index 6607caa12..aa0c70b75 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;
}
@@ -74,6 +80,10 @@ export function wasm(options: RollupWasmOptions = {}): Plugin {
},
transform(code, id) {
+ if (!filter(id)) {
+ return null;
+ }
+
if (code && /\.wasm$/.test(id)) {
const isSync = syncFiles.indexOf(id) !== -1;
const publicFilepath = copies[id] ? `'${copies[id].publicFilepath}'` : null;
diff --git a/packages/wasm/types/index.d.ts b/packages/wasm/types/index.d.ts
index 62921467f..b846f3689 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
@@ -9,6 +10,18 @@ import type { Plugin } from 'rollup';
export type TargetEnv = 'auto' | 'auto-inline' | 'browser' | 'node';
export interface RollupWasmOptions {
+ /**
+ * 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;
+ /**
+ * 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;
/**
* Specifies an array of strings that each represent a WebAssembly file to load synchronously.
*/
@@ -18,7 +31,7 @@ export interface RollupWasmOptions {
* If `maxFileSize` is set to `0` all files will be copied.
* Files specified in `sync` to load synchronously are always inlined, regardless of size.
*/
- maxFileSize?: Number;
+ maxFileSize?: number;
/**
* String used to rename the emitted Wasm files.
*/
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 0db728ed9..4cd256063 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -794,6 +794,10 @@ importers:
version: 4.8.4
packages/wasm:
+ dependencies:
+ '@rollup/pluginutils':
+ specifier: ^5.0.2
+ version: 5.0.4(rollup@3.2.3)
devDependencies:
'@rollup/plugin-typescript':
specifier: ^9.0.1
@@ -2422,6 +2426,21 @@ packages:
rollup: 3.20.2
dev: false
+ /@rollup/pluginutils@5.0.4(rollup@3.2.3):
+ resolution: {integrity: sha512-0KJnIoRI8A+a1dqOYLxH8vBf8bphDmty5QvIm2hqm7oFCFYKCAZWWd2hXgMibaPsNDhI0AtpYfQZJG47pt/k4g==}
+ engines: {node: '>=14.0.0'}
+ peerDependencies:
+ rollup: ^1.20.0||^2.0.0||^3.0.0
+ peerDependenciesMeta:
+ rollup:
+ optional: true
+ dependencies:
+ '@types/estree': 1.0.0
+ estree-walker: 2.0.2
+ picomatch: 2.3.1
+ rollup: 3.2.3
+ dev: false
+
/@sindresorhus/is@4.6.0:
resolution: {integrity: sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==}
engines: {node: '>=10'}