Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davestewart's avatar

Looking for someone to write a gulp plugin

I'm looking for someone to write a gulp plugin.

Its core function is to watch project files, but hook into Tiny LR's fileChanged() function and expose it to the browser, so JavaScript functions can intercept the callback when files on the HD change.

I have one that does this, unfortunately it doesn't seem to run when there's another instance of LR running, and has a lot of extra functionality that I simply don't need - however, it would probably be a good place for someone else to grok the required steps / tasks needed.

Would be great if anyone could help, or put me in touch with someone who could.

Cheers,

Dave

0 likes
4 replies
zachleigh's avatar

Just out of curiosity, what does this do that gulp watch doesnt?

davestewart's avatar

Hey @zachleigh - it provides a hook in the browser when things have changed.

Something along these lines:

<script>
livereload.on('filechanged', function(file)
{
    if(file.match(/\.php$/))
    {
        runCustomFunction(file);
        return false;
    }
})</script>

AFAIK, it's not possible to hook into the existing LR function within the browser - unless you know differently?

The plugin I was using exposes a callback window._onLiveReloadFileChanged, and injects a socket.io script into the page as well, I presume for this purpose (but I don't know for sure).

Saying that, if there was a way to monkeypatch any existing LR JS functionality in the browser, I'd be happy with that too.

davestewart's avatar

Hey, whaddya know - LR does expose its reloading function !

LiveReload.reloader.reload = function(path, options){ console.log(path); }

// /Volumes/Data/Work/Current/2015-07 - Timeslice, Kiosk 3.0/timeslice.kiosk/public/assets/js/all.min.js

Now to see if this works for .php files...

davestewart's avatar
davestewart
OP
Best Answer
Level 11

Boom! Problem solved, in gulp and the browser.

The gulp side was as easy as this:

gulp.watch(src).on('change', function(file){
    livereload.reload(file);
});

And can even be simplified to:

gulp.watch(src).on('change', livereload.reload)

The browser side ended up being a simple monkeypatch:

var reload = LiveReload.reloader.reload;
LiveReload.reloader.reload = function(path, options)
{
    return path.match(/\.php$/)
        ? app.reloadController(path)
        : reload.call(this, path, options);
};

I'm stunned. I've been mucking about with gulp plugins and different configurations for weeks.

Thanks for making me re-look at it @zachleigh !

Please or to participate in this conversation.