Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

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

Closed
@urbanhusky

Description

@urbanhusky

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions