Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Reload watch on configuration change #39

Closed
Grawl opened this issue Aug 22, 2014 · 12 comments
Closed

Reload watch on configuration change #39

Grawl opened this issue Aug 22, 2014 · 12 comments

Comments

@Grawl
Copy link
Contributor

Grawl commented Aug 22, 2014

It would be cool to reload watch task when I change some grunt configurations (like grunt/config/*.js) or install/update something with bower.

@larsonjj
Copy link
Owner

It might be possible to add the grunt config/tasks files to the grunt watch task, PR Welcome :)
As for the bower_components folder, I have tried adding those files to the watch task, but because of the large amount of files each package has, it tends to crash everything 😢.
So for now, I will avoid watching the bower components.

@Grawl
Copy link
Contributor Author

Grawl commented Aug 22, 2014

Okay I will.

We cancompletely remove any node_modules subfolder of bower_components from watch regex with adding !bower_components/**/node_modules or something similar to it's files array. Like this:

        watch: {
            files: [
                'bower_components/**/*',
                '!bower_components/**/node_modules'
            ],
            tasks: 'watch'
        }

I have not tested it yet.

@larsonjj
Copy link
Owner

I hesitate to watch all files even with the negation of node_modules mostly because of the low open file limit on OSX (what I use). Read more (here)[https://github.com/gruntjs/grunt-contrib-watch#how-do-i-fix-the-error-emfile-too-many-opened-files].
I'm thinking it might make more sense to add documentation on the possibility of watching whatever files you want, so the user can make the decision on whether to watch bower_components or not.
Add maybe the example shown could add a little more specificity using file extensions:

watch: {
    files: [
        'bower_components/**/*.{js,scss,css}',
        '!bower_components/**/node_modules'
    ],
    tasks: 'watch'
}

@Grawl
Copy link
Contributor Author

Grawl commented Aug 22, 2014

I know about an issue with many opened files and avoid this with negations. This is a code from my previous Grunt build:

            grunt:
                files:[
                    './*'
                    '<%=locals.path.src%>/<%=locals.path.assets_dev.assets.dir%>/**/*'
                    '!./*.{md,markdown}'
                    ]
                tasks:'build'

It watches for all root files that can change something in result. So if I…

  • Install something with Bower (with --save-dev it changes ./bower.json)
  • Add or change an image
  • Install some Grunt component (with --save-dev it changes ./package.json)

…it fires build task:

    grunt.registerTask 'build', [
        'clean:dev'
        'copy'
        'vendor'
        'styles'
        'scripts'
        'jade'
    ]

And viola, we have an immortal watch that rebuilds everytime when we change somethings that depends on result.

It's not an ideal watch subtask but the way is clear.

@larsonjj
Copy link
Owner

Hmm, this is very interesting. I'll try to test some configurations out to see if I can get live-reloading working with a similar setup to your examples.

Just to give you a heads up, v0.9.9 of yeogurt is up on NPM and has the Grunt config watch task you suggested, so feel free to check it out 👍

@Grawl
Copy link
Contributor Author

Grawl commented Aug 22, 2014

I just made the same locally but added root json files into.

        watch: {
            files: [
                'grunt/**/*',
                '*.{json,js}'
            ],
            tasks: [
                'serve'
            ],
            options: {
                reload: true
            }
        },

So any npm/bower/etc package updates will fire up serve task. We need to fire the same task that is launched because of reload: true just reads config but not launches a build. Now I launch serve because I use it but we can use not only this task with watch, right?

@larsonjj
Copy link
Owner

Good idea and yeah I think you were on the right track.

I just implemented something similar for v0.9.10 that allows you to watch for changes in any any grunt related file as well as any *.json files in the project root. If a change is detected, Gruntfile.js is reloaded and grunt serve is re-run. The kicker is that I run grunt serve:nowatch so it doesn't restart the server or watch tasks and avoids the ERRINUSE error.

You can see the changes here.

@Grawl
Copy link
Contributor Author

Grawl commented Aug 22, 2014

So serve is only task that uses watch?

@larsonjj
Copy link
Owner

Yes, that is correct.

@Grawl
Copy link
Contributor Author

Grawl commented Aug 23, 2014

Good.

@larsonjj
Copy link
Owner

Closing this out as it seems this issue is resolved.

@Grawl
Copy link
Contributor Author

Grawl commented Aug 24, 2014

Completely.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants