diff --git a/README.md b/README.md index 007f559..900c478 100644 --- a/README.md +++ b/README.md @@ -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** diff --git a/lib/index.js b/lib/index.js index d6c468e..e54d9ad 100644 --- a/lib/index.js +++ b/lib/index.js @@ -149,6 +149,7 @@ var defaultOptions = { onBuildStart: [], onBuildEnd: [], onBuildExit: [], + env: {}, dev: true, verbose: false, safe: false @@ -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); } } diff --git a/src/webpack-shell-plugin.js b/src/webpack-shell-plugin.js index b287508..17b4017 100644 --- a/src/webpack-shell-plugin.js +++ b/src/webpack-shell-plugin.js @@ -6,6 +6,7 @@ const defaultOptions = { onBuildStart: [], onBuildEnd: [], onBuildExit: [], + env: {}, dev: true, verbose: false, safe: false @@ -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); } }