About the Build Mode with Webpack

You would build the Webpack bundle for development with:

$ npx webpack --config webpack.config.js --mode=development

and for production with:

$ npx webpack --config webpack.config.js --mode=production

To know whether the current build is in development mode or production mode, you should use webpack.DefinePlugin() in webpack.config.js:

const webpack = require('webpack');

module.exports = (env, argv) => {
    return {
        // other directives...
        plugins: [
            new webpack.DefinePlugin({
                PRODUCTION: JSON.stringify(argv.mode === 'production'),
            }),
        ],
    }
};

Then in your bundled JavaScript files you can have this checking:

if (PRODUCTION) {
    console.log("This is a production build.");
} else {
    console.log("This is a development build.");
}

Note that PRODUCTION here will work not as a global variable, but as a template variable resolved to true or false.

Tips and Tricks Programming Dev Ops JavaScript Webpack

Django/Python Consulting

If you have a specific Django challenge or integration you'd like to solve, I'd be happy to help. Book a free 30-minute call to discuss your project, see if we're a good fit, and explore the best approach for your needs. After the call, you'll receive a tailored cost estimate based on what we discuss.