Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
Can you stop Webpack from bundling unreachable modules because of .env file

So for example:

import axios from 'axios'
 if(process.env.USE_AXIOS) {
    axios.get("/");
 }

in this Axios should not be bundled from Webpack.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are probably couple of ways to handle conditional compilation, but one I know it works is to use dynamic imports

// Just to not throw an exception in the snippet
const process = {
 env:{
   USE_AXIOS: false
 }
}
// ------------------------------------------------






// Solution
if (process.env.USE_AXIOS) {
  import('axios').then(({default: axios}) => {
    if ('get' in axios) {
      console.log('axios in use');
    }
  });
}

full code example is here webpack-conditional-complation

you can examine a produced code

  • here is an axios bundled in separated file
  • here is a compiled ./src/include-axios-base-on-env.js to with-axios.js with flag USE_AXIOS=true
  • here is a compiled ./src/include-axios-base-on-env.js to without-axios.js with flag USE_AXIOS=false
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda