Skip to content

Added environment variables option to spawn function #47

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

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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Once the build finishes, a child process is spawned firing both a python and nod
* `onBuildStart`: array of scripts to execute on the initial build. **Default: [ ]**
* `onBuildEnd`: array of scripts to execute after files are emitted at the end of the compilation. **Default: [ ]**
* `onBuildExit`: array of scripts to execute after webpack's process is complete. *Note: this event also fires in `webpack --watch` when webpack has finished updating the bundle.* **Default: [ ]**
* `env`: Object with environment variables that will be applied to the executables **Default: { }**
* `dev`: switch for development environments. This causes scripts to execute once. Useful for running HMR on webpack-dev-server or webpack watch mode. **Default: true**
* `safe`: switches script execution process from spawn to exec. If running into problems with spawn, turn this setting on. **Default: false**
* `verbose`: **DEPRECATED** enable for verbose output. **Default: false**
Expand Down
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ var defaultOptions = {
onBuildStart: [],
onBuildEnd: [],
onBuildExit: [],
env: {},
dev: true,
verbose: false,
safe: false
Expand Down Expand Up @@ -200,7 +201,9 @@ var WebpackShellPlugin = function () {
command = _serializeScript.command,
args = _serializeScript.args;

var proc = spawn(command, args, { stdio: 'inherit' });
var env = Object.create(global.process.env);
env = Object.assign(env, this.options.env);
var proc = spawn(command, args, { stdio: 'inherit', env: env });
proc.on('close', this.puts);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/webpack-shell-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const defaultOptions = {
onBuildStart: [],
onBuildEnd: [],
onBuildExit: [],
env: {},
dev: true,
verbose: false,
safe: false
Expand Down Expand Up @@ -41,7 +42,9 @@ export default class WebpackShellPlugin {
this.spreadStdoutAndStdErr(exec(script, this.puts));
} else {
const {command, args} = this.serializeScript(script);
const proc = spawn(command, args, {stdio: 'inherit'});
let env = Object.create(global.process.env)
env = Object.assign(env, this.options.env)
const proc = spawn(command, args, {stdio: 'inherit', env: env});
proc.on('close', this.puts);
}
}
Expand Down