Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
Access to Button click handler not executing in a webpack project

I have a very simple setup to understand the webpack basics. Below is my project structure

enter image description here

While running the project and upon clicking on the buttons in the index.html page, the handlers are not getting executed instead log errors in the console.

Please find the project here

This may be a very silly question, but I could not understand this behavior. Hope someone can help me with this. Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can't use the functions unless you export them when you use webpack.

index.js

export function click_blue() { ... }
export function click_red() { ... }

webpack.config.js

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist'),
    library: 'lib',   // add this!
  },
  mode: 'development'
};

index.html

...
<button onclick="lib.click_red()">Red</button>
...

Check webpack output.library for more information.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda