leon13's avatar

Elixir watch loop

Hey folks, I've seen a few issues like this posted on here, and stackoverflow, but still can't wrap my head around it. My Elixir setup is causing a watcher to be set on the public directory, which in turn has my tasks run again. Here's my setup:

elixir(function(mix) {
    mix.sass('app/app.scss')
        .sass('web/web.scss')
        .browserify('main.js')
        .version('js/main.js')
        .browserSync({
            open: false
        });
});

Any help would be greatly appreciated

0 likes
9 replies
leon13's avatar

Here's the output:

[19:11:22] Starting 'all'...
[19:11:22] Starting 'sass'...
[19:11:23] Finished 'sass' after 537 ms
[19:11:23] Starting 'sass'...
[19:11:23] Finished 'sass' after 7.15 ms
[19:11:23] Starting 'browserify'...
[19:11:24] Finished 'browserify' after 1.25 s
[19:11:24] Starting 'version'...
[19:11:24] Finished 'version' after 39 ms
[19:11:24] Starting 'browserSync'...
[19:11:24] Finished 'browserSync' after 106 μs
[19:11:24] Finished 'all' after 1.84 s
[19:11:24] Starting 'default'...
┌───────────────────┬──────────────────────────┬────────────────────────────────────┬────────────────────┐
│ Task              │ Summary                  │ Source Files                       │ Destination        │
├───────────────────┼──────────────────────────┼────────────────────────────────────┼────────────────────┤
│ mix.sass()        │ 1. Compiling Sass        │ resources/assets/sass/app/app.scss │ public/css/app.css │
│                   │ 2. Autoprefixing CSS     │                                    │                    │
│                   │ 3. Concatenating Files   │                                    │                    │
│                   │ 4. Writing Source Maps   │                                    │                    │
│                   │ 5. Saving to Destination │                                    │                    │
├───────────────────┼──────────────────────────┼────────────────────────────────────┼────────────────────┤
│ mix.sass()        │ 1. Compiling Sass        │ resources/assets/sass/web/web.scss │ public/css/web.css │
│                   │ 2. Autoprefixing CSS     │                                    │                    │
│                   │ 3. Concatenating Files   │                                    │                    │
│                   │ 4. Writing Source Maps   │                                    │                    │
│                   │ 5. Saving to Destination │                                    │                    │
├───────────────────┼──────────────────────────┼────────────────────────────────────┼────────────────────┤
│ mix.browserify()  │                          │ resources/assets/js/main.js        │ public/js/main.js  │
├───────────────────┼──────────────────────────┼────────────────────────────────────┼────────────────────┤
│ mix.version()     │ 1. Versioning            │ public/js/main.js                  │ public/build       │
│                   │ 2. Rewriting File Paths  │                                    │                    │
│                   │ 3. Saving to Destination │                                    │                    │
├───────────────────┼──────────────────────────┼────────────────────────────────────┼────────────────────┤
│ mix.browserSync() │ 1. Starting Browsersync  │
└───────────────────┴──────────────────────────┴────────────────────────────────────┴────────────────────┘
[19:11:24] Finished 'default' after 11 ms
[19:11:24] Starting 'watch'...
[19:11:24] Finished 'watch' after 42 ms
[BS] Watching files...
[BS] File changed: public/build/rev-manifest.json
[19:11:32] 1391468 bytes written (8.09 seconds)
[BS] File changed: public/js/main.js
[19:11:34] Starting 'version'...
┌───────────────┬──────────────────────────┬───────────────────┬──────────────┐
│ Task          │ Summary                  │ Source Files      │ Destination  │
├───────────────┼──────────────────────────┼───────────────────┼──────────────┤
│ mix.version() │ 1. Copying Source Maps   │ public/js/main.js │ public/build │
│               │ 2. Versioning            │                   │              │
│               │ 3. Rewriting File Paths  │                   │              │
│               │ 4. Saving to Destination │                   │              │
└───────────────┴──────────────────────────┴───────────────────┴──────────────┘
[19:11:34] Finished 'version' after 56 ms
[BS] File changed: public/build/rev-manifest.json
ejdelmonico's avatar

Try removing browsersync and see if it works normally.

leon13's avatar

It's better, but the version task still runs twice:

[20:12:57] Starting 'all'...
[20:12:57] Starting 'sass'...
[20:12:57] Finished 'sass' after 684 ms
[20:12:57] Starting 'sass'...
[20:12:57] Finished 'sass' after 15 ms
[20:12:57] Starting 'browserify'...
[20:12:59] Finished 'browserify' after 1.32 s
[20:12:59] Starting 'version'...
[20:12:59] Finished 'version' after 39 ms
[20:12:59] Finished 'all' after 2.06 s
[20:12:59] Starting 'default'...
┌──────────────────┬──────────────────────────┬────────────────────────────────────┬────────────────────┐
│ Task             │ Summary                  │ Source Files                       │ Destination        │
├──────────────────┼──────────────────────────┼────────────────────────────────────┼────────────────────┤
│ mix.sass()       │ 1. Compiling Sass        │ resources/assets/sass/app/app.scss │ public/css/app.css │
│                  │ 2. Autoprefixing CSS     │                                    │                    │
│                  │ 3. Concatenating Files   │                                    │                    │
│                  │ 4. Writing Source Maps   │                                    │                    │
│                  │ 5. Saving to Destination │                                    │                    │
├──────────────────┼──────────────────────────┼────────────────────────────────────┼────────────────────┤
│ mix.sass()       │ 1. Compiling Sass        │ resources/assets/sass/web/web.scss │ public/css/web.css │
│                  │ 2. Autoprefixing CSS     │                                    │                    │
│                  │ 3. Concatenating Files   │                                    │                    │
│                  │ 4. Writing Source Maps   │                                    │                    │
│                  │ 5. Saving to Destination │                                    │                    │
├──────────────────┼──────────────────────────┼────────────────────────────────────┼────────────────────┤
│ mix.browserify() │                          │ resources/assets/js/main.js        │ public/js/main.js  │
├──────────────────┼──────────────────────────┼────────────────────────────────────┼────────────────────┤
│ mix.version()    │ 1. Versioning            │ public/js/main.js                  │ public/build       │
│                  │ 2. Rewriting File Paths  │                                    │                    │
│                  │ 3. Saving to Destination │                                    │                    │
└──────────────────┴──────────────────────────┴────────────────────────────────────┴────────────────────┘
[20:12:59] Finished 'default' after 12 ms
[20:12:59] Starting 'watch'...
[20:12:59] Finished 'watch' after 49 ms
[20:13:06] 1391467 bytes written (7.06 seconds)
[20:13:07] Starting 'version'...
┌───────────────┬──────────────────────────┬───────────────────┬──────────────┐
│ Task          │ Summary                  │ Source Files      │ Destination  │
├───────────────┼──────────────────────────┼───────────────────┼──────────────┤
│ mix.version() │ 1. Copying Source Maps   │ public/js/main.js │ public/build │
│               │ 2. Versioning            │                   │              │
│               │ 3. Rewriting File Paths  │                   │              │
│               │ 4. Saving to Destination │                   │              │
└───────────────┴──────────────────────────┴───────────────────┴──────────────┘
[20:13:07] Finished 'version' after 55 ms
ejdelmonico's avatar

It shouldn't matter but try using array brackets for the js file in version method. I guess its worth a try.

leon13's avatar

Yeah, that's what I had originally, but removed them to try and simplify

ejdelmonico's avatar

It could be that browserify is not finished when version tries to run...hence, it runs again when it finishes. Try using a second mix with just the versioning.

elixir((mix) => {
  mix.version(['js/main.js']);
}

Also, delete your old build, js and css directories before runing.

ryanrca's avatar

I'm getting the exact same issue. gulp watch is watching the cache busting directory of public/build/...

So it goes into an infinite loop, and eventually crashes. It would be great if we can pass mix.browserSync() an ignore directory, but I haven't figured out if that's even possible yet.

On further inspection, it's actually watching everything in public/... In opinion, public/ should not be watched at all!

Is there a way to declare ignore directory?

1 like

Please or to participate in this conversation.