Skip to content

Commit a1f6f22

Browse files
committed
add option to specify environment variables
1 parent 72df281 commit a1f6f22

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The minimum required `wasm-pack` version is `0.8.0`
2424

2525
## Linting
2626

27-
This project uses the `prettier` with default configuration. Fo manually format the code run the `lint:fix` script.
27+
This project uses the `prettier` with default configuration. To manually format the code run the `lint:fix` script.
2828

2929
## Usage
3030

@@ -79,7 +79,13 @@ module.exports = {
7979

8080
// Controls plugin output verbosity, either 'info' or 'error'.
8181
// Defaults to 'info'.
82-
// pluginLogLevel: 'info'
82+
// pluginLogLevel: 'info',
83+
84+
// If defined, sets the specified environment variables during compilation.
85+
//
86+
// env: {
87+
// WASM_BINDGEN_THREADS_STACK_SIZE: 128 * 2 ** 10
88+
// }
8389
}),
8490
],
8591

plugin.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface WasmPackPluginOptions {
1111
watchDirectories?: string[]
1212
/** Controls plugin output verbosity. Defaults to 'info'. */
1313
pluginLogLevel?: 'info' | 'error'
14+
env?: Record<string, string>
1415
}
1516

1617
export default class WasmPackPlugin {

plugin.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class WasmPackPlugin {
6464
this.wp = new Watchpack()
6565
this.isDebug = true
6666
this.error = null
67+
this.env = options.env
6768
}
6869

6970
apply(compiler) {
@@ -123,7 +124,7 @@ class WasmPackPlugin {
123124

124125
_makeEmpty() {
125126
try {
126-
fs.mkdirSync(this.outDir, {recursive: true})
127+
fs.mkdirSync(this.outDir, { recursive: true })
127128
} catch (e) {
128129
if (e.code !== 'EEXIST') {
129130
throw e
@@ -178,6 +179,7 @@ class WasmPackPlugin {
178179
cwd: this.crateDirectory,
179180
args: this.args,
180181
extraArgs: this.extraArgs,
182+
env: this.env,
181183
})
182184
})
183185
.then((detail) => {
@@ -203,7 +205,15 @@ class WasmPackPlugin {
203205
}
204206
}
205207

206-
function spawnWasmPack({ outDir, outName, isDebug, cwd, args, extraArgs }) {
208+
function spawnWasmPack({
209+
outDir,
210+
outName,
211+
isDebug,
212+
cwd,
213+
args,
214+
extraArgs,
215+
env,
216+
}) {
207217
const bin = findWasmPack()
208218

209219
const allArgs = [
@@ -220,6 +230,13 @@ function spawnWasmPack({ outDir, outName, isDebug, cwd, args, extraArgs }) {
220230
const options = {
221231
cwd,
222232
stdio: 'inherit',
233+
env:
234+
env != null
235+
? {
236+
...process.env,
237+
...env,
238+
}
239+
: undefined,
223240
}
224241

225242
return runProcess(bin, allArgs, options)

0 commit comments

Comments
 (0)