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

201
Vistas
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 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