Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to specify environment variables #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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