Pass webpack 2 build environment arguments, e.g. --env.production, in webpack dev middleware #881

Closed
opened 2025-08-09 17:18:02 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @urbanhusky on 3/28/2017

Hi,

I've got the following webpack.config.js file in which I've added a guard clause to check that the build environment is properly injected (as it should be for webpack 2).

module.exports = function (env) {
    if (env == null) {
        console.log("Environment is not set up. Webpack needs --env.dev or --env.prod arguments, passed to module.exports function(env)");
        throw new Error("Environment is not set up. Webpack needs --env.dev or --env.prod arguments, passed to module.exports function(env)");
    }
    if (env.prod) {
        return require('./config/webpack.prod.js');
    } else {
        return require('./config/webpack.dev.js');
    }
}

However, when I try to run the application with hot module replacement (i.e. in development), env is undefined.

The Code in Startup.cs looks like this:

if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();

               app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true });
            }

How can I fix this? (process.argv.indexOf is no longer supported in webpack 2)

*Originally created by @urbanhusky on 3/28/2017* Hi, I've got the following `webpack.config.js` file in which I've added a guard clause to check that the build environment is properly injected (as it should be for webpack 2). ```js module.exports = function (env) { if (env == null) { console.log("Environment is not set up. Webpack needs --env.dev or --env.prod arguments, passed to module.exports function(env)"); throw new Error("Environment is not set up. Webpack needs --env.dev or --env.prod arguments, passed to module.exports function(env)"); } if (env.prod) { return require('./config/webpack.prod.js'); } else { return require('./config/webpack.dev.js'); } } ``` However, when I try to run the application with hot module replacement (i.e. in development), `env` is undefined. The Code in `Startup.cs` looks like this: ```C# if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true }); } ``` How can I fix this? (`process.argv.indexOf` is no longer supported in webpack 2)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#881
No description provided.