Search code examples
symfonyguardlivereload

How can I get livereload to work with symfony2 (using guard?)


I have had livereload working with guard in my symfony site. But my assets (css/js) were in the 'web' directory. But then I learned that the best practice is to keep everything in 'src' so that you can keep all your files as a bundle. So I moved it to the Resources/public directory in my bundle under my 'src' dir and ran:

php app/console assets:install target [--symlink]

This created the necessary symbolic links from 'web' to my 'src' assets, everything seems to work if I run guard in 'src/.../Resources/public', sass, compass, however live reload no longer works. I'm wondering if it has anything to do with the symbolic links (it was working before, I'm using livereload.js) I've read here:

symfony2 assetic dump stopped watch

and here:

No route found for "GET /img/glyphicons-halflings.png"

that people have got livereload to work with symfony/guard/sass. The trick, I assume is to write the Guardfile such that it runs the assets: install or assetic:dump, which I guess is what makes livereload work? But I can't find anyone explaining how they got this set (symfony2, livereload, sass, guard) to work (maybe just the Guardfile?).


Solution

  • The bundle may be the better method. But all I ended up doing was downloading liveload.js from their site, adding it a javascript include, added this to my Guardfile:

    guard 'livereload' do
     watch(%r{.+\.(css|html|js)$})
    end
    

    and ran guard manually.