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

170
Vistas
What is the difference between hardcoding a string and using a variable containing a string when referencing an object? Affects Webpack tree shaking

It feels like these forEach loops should be equivalent but somehow the variable causes the Webpack tree shaking (I assume) to be much less aggressive, and my project is structured in a way where I need it to be aggressive. Code is stripped down to show just the issue mentioned. For context I'm building a boilerplate that allows the user/client to use flexible drag and drop modules that represent React Components.

// AllModules = Object of React Components
moduleNames = ['ModuleName'];

moduleNames.forEach((name) => {
    const Module = AllModules[name]; // Webpack compiles assets for every component in AllModules
});

moduleNames.forEach((name) => {
    const Module = AllModules['ModuleName']; // Webpack compiles only the assets for ModuleName
});

I'd rather not mess with Webpack settings if possible, that always seems to open up a can of worms, but I will if necessary. Is there any way to use the variable that behaves exactly as the hardcoded string does?

about 4 years ago · Juan Pablo Isaza
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