Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!