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

250
Vistas
Generating a main script and a some libraries/modules with Webpack 5

I'm trying to build a web application made one main entry point (index.js) and a number of modules that I want to load dynamically.

Something like:

index.js
document.getElementById('button1').addEventListener('click', async function(){
  const mod = await import('module1.js');
  mod.run();
});
module1.js
export function run() {
  console.log("Hello from module1");
}

Is it possible to build a bundle for each of these files using Webpack 5?

What I tried

output.library (but it builds everything as libraries)
  1. It seems that Webpack lets me set multiple entry points.

  2. However to expose all of module1.js's exports I need to set output.library.

  3. But if I do, then index.js is built as a library too, since there can be only one output field.

Multiple configurations (but it breaks the dev server)

I could configure Webpack to build both my main script and the modules using multiple configurations, but if I try this, then the webpack-dev-server tries to start two instances and fails.

It prints errors like:

<e> [webpack-dev-middleware] ConcurrentCompilationError: You ran Webpack twice. Each instance only supports a single concurrent compilation at a time.

What else can I try?

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

0

Found an answer: the correct way to do this is to use a dynamic import. By default Webpack places the dynamically-imported resource in different files.

More documentation:

  • Code Splitting
  • Lazy Loading
  • Dynamic expressions in import()
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