question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When used with gulp watch all js files are being rebuilt

See original GitHub issue

When webpack-stream is used in a gulp watch task it rebuilds all files, resulting in slow compile time.

This is my gulpfile with all webpack settings within:

var gulp = require('gulp'),
    util = require('gulp-util'),
    sass = require('gulp-sass'),
    webpack = require('webpack');
    webpackStream = require('webpack-stream');

gulp.task('webpack', function () {
    return gulp.src('./build/scripts/entry.js')
        .pipe(webpackStream({
            entry: './build/scripts/entry.js',
            output: {
                path: __dirname + '/public/scripts',
                filename: 'bundle.js'
            },
            resolve: {
                extensions: ['', '.webpack.js', '.web.js', '.js', '.ts']
            }
        }, webpack, function (err, stats) {
            console.log(stats.toString({ colors: true }));
        }))
        .pipe(gulp.dest('./public/scripts'));
});

gulp.task('scss', function () {
    return gulp.src('./build/styles/**/*.scss')
        .pipe(sass())
        .pipe(gulp.dest('./public/styles'));
});

gulp.task('watch', function () {
    gulp.watch('./build/scripts/**/*.js', ['webpack']);
    gulp.watch('./build/styles/**/*.scss', ['scss']);
});

If I just use webpack --watch, only the edited file will be rebuilt, not working with above gulp webpack-stream.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
aventiccommented, Aug 19, 2016

@jswny If I run my task webpack it will build my files, if I add watch: true, then I can’t run multiple task etc: gulp.task('build', ['webpack', 'styles']);. It will still be in watch mode and not execute following tasks. Makes sense?

But I found a way, if I do a simple gulp watch and watch my files instead of adding watch: true I will achieve what I want. Just got confused by the whole, where to watch as the readme had an example to use it inside my webpack config.

1reaction
aventiccommented, Aug 19, 2016

I dont know if it’s fixed, definitely required some workaround and alot of fiddle. I’m closing for now, hopefully others who end in my struggle can learn from this 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I watch multiple files with gulp-browserify but process ...
Just call a normal task on file change, like this: gulp.task("build-js", function() { return gulp.src('src/js/app.js') .pipe(browserify()) ...
Read more >
Watching Files | gulp.js
The watch() API connects globs to tasks using a file system watcher. It watches for changes to files that match the globs and...
Read more >
gulp watch not watching js files ? - Laracasts
Hello. I am using Gulp with Elixir and coffee script but it only compiles what i make a change in the less files...
Read more >
Moving from gulp 3 to 4 | Web Development - UConn Blogs
In both cases, the result will be basically the same. When the command gulp watch is run, the sass and js files will...
Read more >
Using Gulp 4 in your workflow for Sass and JS files
gulp — runs everything in the gulpfile.js. We're exporting just the specific gulp functions that we will be using, like src , dest...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found