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

205
Visualizações
Why is the script executed multiple times?

I have a problem. When you click on the button, the text should be output to the console. But it is output several times

const headerNavigation = document.querySelector('.open-header');
headerNavigation.addEventListener('click', () => {
    console.log('ok')
})

I use gulp with webpack-stream, this problem only occurs when gulp is enabled. If I open index.html from the file manager, then everything works fine for me.

Here is the task

function scripts () {
    return src('app/js/app.js')
    .pipe(webpack({
        mode   : 'production',
        performance: { hints: false },
        output : {
            filename : 'app.min.js'
        },
        module : {
            rules : [
                {
                    test    : /\.js$/,
                    exclude : /(node_modules)/,
                    use: {
                        loader: 'babel-loader',
                        options: {
                            presets: ['@babel/preset-env'],
                            plugins: ['babel-plugin-root-import']
                        }
                    }
                    // query: {
                    //  presets: ['@babel/env'],
                    //  plugins: ['babel-plugin-root-import']
                    // }
                }
            ]
        },
        optimization: {
            minimize: true,
            splitChunks : {
                chunks : 'all'
            }
        },
    }))
    .pipe(dest('app/js'))
    .pipe(browserSync.stream())
}

Using the poke method, I realized that the problem is in browser-sync. I was advised to change browser Sync.stream() to browser Sync.reload(), but I just get an error

I will be very grateful if you can help me

about 4 years ago · Santiago Gelvez
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