diff --git a/package.json b/package.json index 883b31e..0f7bb31 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ }, "devDependencies": { "@types/webpack": "*", + "@types/watchpack": "*", "prettier": "^2.4.1" } } diff --git a/plugin.d.ts b/plugin.d.ts index 764cc89..5f657be 100644 --- a/plugin.d.ts +++ b/plugin.d.ts @@ -1,4 +1,5 @@ import { Compiler } from 'webpack' +import { WatchOptions } from 'watchpack' export interface WasmPackPluginOptions { crateDirectory: string @@ -9,6 +10,7 @@ export interface WasmPackPluginOptions { outDir?: string outName?: string watchDirectories?: string[] + watchOptions?: WatchOptions /** Controls plugin output verbosity. Defaults to 'info'. */ pluginLogLevel?: 'info' | 'error' } diff --git a/plugin.js b/plugin.js index df1597d..41492dd 100644 --- a/plugin.js +++ b/plugin.js @@ -61,7 +61,11 @@ class WasmPackPlugin { info = () => {} } - this.wp = new Watchpack() + // May need to adjust this default since this is potentialy computation heavy + this.watchOptions = Object.assign( + { aggregateTimeout: 300 }, + options.watchOptions + ) this.isDebug = true this.error = null } @@ -71,10 +75,18 @@ class WasmPackPlugin { ? this.forceMode === 'development' : compiler.options.mode === 'development' + this.watchOptions = Object.assign( + compiler.options.watchOptions, + this.watchOptions + ) + // This fixes an error in Webpack where it cannot find // the `pkg/index.js` file if Rust compilation errors. this._makeEmpty() + // Move Watchpack initialization here so we can pass watchOptions to it + this.wp = new Watchpack(this.watchOptions) + // force first compilation compiler.hooks.beforeCompile.tapPromise('WasmPackPlugin', () => { if (this._ranInitialCompilation === true) {