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

256
Vistas
How to write a webpack plugin to replace require function to its source code

Say we have a util.js contains functions a and b:

// util.js
export function a() {
  ...
}

export function b() {
  ...
}

And I require them in index.js:

// index.js
export default function main() {
  const {a, b} = require('./util');
  
  ...
  a(); // use them somewhere
  b(); 
}

But I want to replace the require function to its source code like this before the bundling:

// replaced index.js
export default function main() {
  const a = function () {
    // ... source code from util.js
  };
  const b = function () {
    // ... source code from util.js
  };
  
  ...
  a(); // use them somewhere
  b();
}

I'm not that familiar with webpack plugins and hooks API. Is this possible and if yes, how to do it?

Thanks!

One solution not that clever, do string replace directly by string-replace-loader.

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