Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
Detecting Webpack mode in JavaScript files

I am building a bundle of ReactJS files with Webpack.

Is it possible to detect inside of JSX files which Webpack mode is being used: "none", "development", or "production"?

For example, I would like some console.log() statements and global variables in development mode but not production.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

One can 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, webpack.DefinePlugin() should be used 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 the bundled JavaScript files one 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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda