Roots Discourse

Grunt not auto reloading browser after file changes

hi. i’m having a bit of trouble with getting grunt to auto-reload after i make changes to my css and html.

i know livereload was deprecated and now comes built into grunt-contrib-watch so i’m not too sure why it’s not reloading automatically?

looking over the web there seem to be few solutions but none seem to work for the roots theme. is there something i have to change in the gruntfile.js to get livereload to work?

i’ve just got my head around the idea of grunt so i apologise if the solution is obvious.

any help would be much appreciated. many thanks!

Relevant PR maybe: https://github.com/roots/roots/pull/856

You still need to enable livereload in your Gruntfile even though its been merged into grunt-contrib-watch. You also need a browser plugin or a script tag added like that PR above mentions.

1 Like

hi swalkinshaw,

thanks for the heads up regarding that PR.

i’ve enabled in my roots theme and set to true

i’ve also added the script tag just before the </body> – i’ve stuck it in base.php for now. not sure if thats correct?

but still no luck.

if i can be a bit cheeky and ask a massive favour. if you were going to get livereload working on roots what would you do exactly?

thanks for the help!

EDIT:

actually, its working. woo hoo!

i’ve enabled liverload using the PR you supplied and put the script in base.php – still not sure if thats good practice but it’ll do for now.

thanks again!

EDIT AGAIN:

it’s working but only for css and js changes. not html – php files are not reloading.

hi wesley,

i just posted an edit to my above post. it was working all along. great work. thanks!

EDIT:

actually. just noticed a problem. it only reloads when i change the css or js. it’s not reloading the php files when i edit the html.

I’ve just updated the PR to add .php files to the livereload file list.

1 Like

thanks wesley. you are a star! this works perfectly.

lets hope this gets merged into the master.

Keep in mind that you don’t want to leave that script tag in the production version of your theme. That’s one of the reasons we don’t enable livereload in Roots by default.

That’s exactly why I prefer the browser plugin, with it you don’t need to add any additional script tags.

Since two commits were made for live reload, wouldn’t it also be good to add “//localhost:35729/livereload.js” to the $assets of the development environment scripts.php file? Maybe only enable it if livereload is set to “true” in the grunfile.js?

Because of the reason that @weslly mentioned — just use the browser plugin