Skip to content

Commit

Permalink
add option to specify environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jrvidal committed Jul 29, 2022
1 parent 72df281 commit a1f6f22
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The minimum required `wasm-pack` version is `0.8.0`

## Linting

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

## Usage

Expand Down Expand Up @@ -79,7 +79,13 @@ module.exports = {

// Controls plugin output verbosity, either 'info' or 'error'.
// Defaults to 'info'.
// pluginLogLevel: 'info'
// pluginLogLevel: 'info',

// If defined, sets the specified environment variables during compilation.
//
// env: {
// WASM_BINDGEN_THREADS_STACK_SIZE: 128 * 2 ** 10
// }
}),
],

Expand Down
1 change: 1 addition & 0 deletions plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface WasmPackPluginOptions {
watchDirectories?: string[]
/** Controls plugin output verbosity. Defaults to 'info'. */
pluginLogLevel?: 'info' | 'error'
env?: Record<string, string>
}

export default class WasmPackPlugin {
Expand Down
21 changes: 19 additions & 2 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class WasmPackPlugin {
this.wp = new Watchpack()
this.isDebug = true
this.error = null
this.env = options.env
}

apply(compiler) {
Expand Down Expand Up @@ -123,7 +124,7 @@ class WasmPackPlugin {

_makeEmpty() {
try {
fs.mkdirSync(this.outDir, {recursive: true})
fs.mkdirSync(this.outDir, { recursive: true })
} catch (e) {
if (e.code !== 'EEXIST') {
throw e
Expand Down Expand Up @@ -178,6 +179,7 @@ class WasmPackPlugin {
cwd: this.crateDirectory,
args: this.args,
extraArgs: this.extraArgs,
env: this.env,
})
})
.then((detail) => {
Expand All @@ -203,7 +205,15 @@ class WasmPackPlugin {
}
}

function spawnWasmPack({ outDir, outName, isDebug, cwd, args, extraArgs }) {
function spawnWasmPack({
outDir,
outName,
isDebug,
cwd,
args,
extraArgs,
env,
}) {
const bin = findWasmPack()

const allArgs = [
Expand All @@ -220,6 +230,13 @@ function spawnWasmPack({ outDir, outName, isDebug, cwd, args, extraArgs }) {
const options = {
cwd,
stdio: 'inherit',
env:
env != null
? {
...process.env,
...env,
}
: undefined,
}

return runProcess(bin, allArgs, options)
Expand Down

0 comments on commit a1f6f22

Please sign in to comment.