Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"devDependencies": {
"@types/webpack": "*",
"@types/watchpack": "*",
"prettier": "^2.4.1"
}
}
2 changes: 2 additions & 0 deletions plugin.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Compiler } from 'webpack'
import { WatchOptions } from 'watchpack'

export interface WasmPackPluginOptions {
crateDirectory: string
Expand All @@ -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'
}
Expand Down
14 changes: 13 additions & 1 deletion plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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) {
Expand Down