Alexey Berezkin
Alexey Berezkin

Reputation: 1543

Detect from bundled code that it was compiled in development mode

There is process.env.NODE_ENV==='development' but that's defined on server side which runs webpack or its dev-server. I need to determine it from the bundled code which runs in a browser.

Upvotes: 2

Views: 632

Answers (1)

Marco
Marco

Reputation: 7287

You can use webpack.DefinePlugin in the building process to define a global variable like this:

//
const mode = "production"

module.exports = {
    mode: mode,
    // ...
    plugins: [
        new webpack.DefinePlugin({
            __mode__: JSON.stringify(mode)
        })
    ]
}

Then you can access __mode__.

Upvotes: 2

Related Questions