gruntjs / grunt-contrib-watch

Run tasks whenever watched files change.
http://gruntjs.com/
MIT License
1.98k stars 356 forks source link

Multiple watch configurations? #541

Open kristianmandrup opened 7 years ago

kristianmandrup commented 7 years ago

Trying to set up different watch configurations for dev vs prod What am I missing?

 Verifying property watch.dev.files exists in config...ERROR
    >> Unable to process task.
    Warning: Required config property "watch.dev.files" missing.
        concurrent: {
            dev: {
                tasks: ['nodemon', 'watch:dev'],
                options: {
                    logConcurrentOutput: true
                }
            },
            prod: {
                tasks: ['nodemon', 'watch:prod'],
                options: {
                    logConcurrentOutput: true
                }
            }
        },
        watch: {
            prod: {
                js: {
                    files: [
                        'editor/js/**/*.js'
                    ],
                    tasks: ['copy:build', 'concat', 'uglify', 'attachCopyright:js']
                },
                sass: {
                    files: [
                        'editor/sass/**/*.scss'
                    ],
                    tasks: ['sass', 'attachCopyright:css']
                },
                json: {
                    files: [
                        'nodes/core/locales/en-US/messages.json',
                        'red/api/locales/en-US/editor.json',
                        'red/runtime/locales/en-US/runtime.json'
                    ],
                    tasks: ['jsonlint:messages']
                },
                keymaps: {
                    files: [
                        'editor/js/keymap.json'
                    ],
                    tasks: ['jsonlint:keymaps', 'copy:build']
                },
                misc: {
                    files: [
                        'CHANGELOG.md'
                    ],
                    tasks: ['copy:build']
                }
            },
            dev: {
                js: {
                    files: [
                        'editor/js/**/*.js'
                    ],
                    tasks: ['copy:build', 'concat', 'babel']
                },
                sass: {
                    files: [
                        'editor/sass/**/*.scss'
                    ],
                    tasks: ['sass', 'attachCopyright:css']
                },
                json: {
                    files: [
                        'nodes/core/locales/en-US/messages.json',
                        'red/api/locales/en-US/editor.json',
                        'red/runtime/locales/en-US/runtime.json'
                    ],
                    tasks: ['jsonlint:messages']
                },
                keymaps: {
                    files: [
                        'editor/js/keymap.json'
                    ],
                    tasks: ['jsonlint:keymaps', 'copy:build']
                },
                misc: {
                    files: [
                        'CHANGELOG.md'
                    ],
                    tasks: ['copy:build']
                }
            }
johnruane commented 7 years ago

This is too many levels deep.

watch: {
  prod: {
    js: {

Can you prefix your watch tasks with 'prod' or 'dev', then call them like so:

tasks: ['nodemon', 'watch:dev_js', 'watch:dev_sass']

aaronjpitts commented 7 years ago

tasks: ['nodemon', 'watch:dev_js', 'watch:dev_sass'] doesn't work, it will only run the first watch task (watch:dev_js in this case)

Samvanst commented 5 years ago

Hey i had the same issue and did the same logic as you but that didn't work. The working solution and working like a charm is this one: https://stackoverflow.com/questions/13833196/gruntjs-watch-different-folders-and-execute-tasks Hope this helps. you need to install the grunt plugin: https://www.npmjs.com/package/grunt-focus then add like you tried with concurrent: this code

focus: { develop: { include: ['dev'] }, master: { include: ['prod'] }, },

and make ure tasks like this:

grunt.registerTask('dev', 'compile develop', ['focus:develop']); grunt.registerTask('prod', 'compile production', ['focus:master']);