B
B
Bogdan Odarchenko2016-02-20 02:26:37
Node.js
Bogdan Odarchenko, 2016-02-20 02:26:37

Vue.js + Webpack + Gulp how to implement HMR for JS?

I ran into a problem how to update js scripts within this assembly without reloading the entire page.
Assembly link www.fayloobmennik.net/5815874
The task that collects for the first time

gulp.task('serve', ['styles', 'vendor', 'watch'], function () {
    browserSync.init({
        browser: "google chrome",
        proxy: {
            target: "prodacton",
            middleware: [
                webpackDevMiddleware(compiler, {
                    // IMPORTANT: dev middleware can't access config, so we should
                    // provide publicPath by ourselves
                    publicPath: '/site/templates/scripts/',
                    stats: {
                        colors: true,
                        chunks: false
                    },
                    // for other settings see
                    // http://webpack.github.io/docs/webpack-dev-middleware.html
                }),
                // compiler should be the same as above
                webpackHotMiddleware(compiler)
            ]
        },
    });
});

Here is the observer
// Watch
gulp.task('watch', function () {

    // Watch for changes in `app` folder
    gulp.watch([
        config.app + '/**/*.php',
        config.app + '/**/*.inc',
        config.app + '/images/**/*'
    ]).on('change', browserSync.reload);

    // Watch .sass files
    gulp.watch(config.app + '/styles/**/*.scss', ['styles']);

});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question