Grunt Live Reload and _main.js Not Working

I’ve tested on a clean Roots install and can’t get my edits in _main.js to load with LiveReload enabled. I’m on a windows machine. If I manually grunt the theme it packages it up properly but not when watch is enabled. I’m not sure what the issue is here with that file or if it’s something I’m doing wrong. I’m using the standard Grunt.js file within Roots with no edits. LESS reloads properly but _main.js doesn’t seem to. Any help is appreciated!

It appears certain comments within the _main.js file causes the file to be deleted by Grunt recess - I don’t like this, has anyone experienced this? For example:

function initAccordions() {

jQuery('.accordion-toggle').each(function () {

//        Accordions Click
        var toggle = jQuery(this);
        jQuery(toggle).on('click', function () {

//            Remove any toggled icons
//            jQuery(toggle).parents('.panel-group').find('.glyphicons').removeClass('glyphicon-minus').addClass('glyphicon-minus');
            jQuery(toggle).children('.glyphicon').addClass('glyphicon-minus');


        });

    });

}

Causes the file to be deleted on my end (be sure to run the function).

OK - So after much troubleshooting I’ve narrowed it down to the jshint task. Whenever it runs on my system apparently it blocks the other tasks from running after. If I remove the jshint task from the live reload it works fine.

It should only stop Grunt running if there is a problem (or it thinks there is a problem) with the code. Where are you putting your code? Try putting it in a separate file in plugins instead of _main.js.

I’ve never ran Grunt from Windows, but after you save _main.js, the CLI should tell you if Grunt watch is running, what the issue is that it doesn’t like in the Javascript file and what you need to fix.

I don’t think Grunt runs as well on Windows… perhaps it’s node js related. I really need to get a Mac. For now, I’ve simply some jshint task from running and all seems working well.

You could always try out Linux if you have some patience. I love now that I work on it on a daily basis :smile:

Removing jshint works as well, it’s used to make sure you don’t have any errors in your javascript, but can sometimes be pretty strict.

Anything has to be better than windows…

Haha! I don’t mind Windows all that much… but I just like how Linux works (I’m on Linux Mint right now). And yeah, for things like Node.js, Grunt, and understanding how web servers run, it’s great.

1 Like