Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt - Watch Task is not working

It seems like my watch task in my project grunt file is starting up then quitting straight away.

Please review the screenshot attached.

Please find the code for my Gruntfile.js;

module.exports = function (grunt) {

    grunt.initConfig({
        sass: {
            options: {
                cacheLocation: '.sass-cache'
            },
            prod: {
                options: {
                    style: 'compressed'
                },
                files: [{
                    'assets/css/dist/main.min.css': 'assets/css/sass/main.scss'
                }]
            },
            dev: {
                options: {
                    style: 'nested'
                },
                files: [{
                    'assets/css/main.css': 'assets/css/sass/main.scss'
                }]
            }
        },
        imageoptim: {
          files: [
            'img/flat',
            'img/flat/**'
          ],
          options: {
            imageAlpha: true,
            jpegMini: true,
            quitAfter: true
          }
        },
        uglify: {
            options: {
              mangle: true,
              compress: true
            },
            jsCompress: {
                files: {
                    'js/dist/main.min.js': ['js/src/script1.js', 'js/src/script2.js']
            }
          }
        },
        concat: {
            options: {
                separator: ';',
          },
          dist: {
                src: ['js/src/script1.js', 'js/src/script2.js'],
                dest: 'js/dist/main.min.js',
          }
        },
        watch: {
            sassWatch: {
                files: 'css/sass/**/*.scss',
                tasks: ['sass:prod', 'sass:dev'],
            },
            JsWatch: {
                files: ['js/modules/script1.js', 'js/modules/script2.js'],
                tasks: ['uglify:jsCompress', 'concat:dist'],
            }
        },
        notify: {
            sassNotify: {
                options: {
                    title: "Task Complete",
                    message: "Your Sass has been compiled and concatanatated!"
                }
            },
            jsNotify: {
                options: {
                    title: "Task Complete",
                    message: "Your JS has been minified and concatanatated!"
                }
            },
            imageNotify: {
                options: {
                    title: "Task Complete",
                    message: "All images have been compressed"
                }
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-imageoptim');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-notify');

    grunt.registerTask('sassNotify', 'watch:sassWatch');
    grunt.registerTask('jsNotify', 'watch:jsWatch');
    grunt.registerTask('imageNotify', 'imageoptim');

};

Does anyone have an idea why this is happening?

Kind Regards,

B!

enter image description here

like image 872
PI. Avatar asked Feb 15 '23 14:02

PI.


2 Answers

My problem was that it was watching to much i had 100+ image files that it was keeping track of so i just specified what it should watch (js, html, scss, css).

like image 190
James Harrington Avatar answered Feb 18 '23 11:02

James Harrington


I ran into the issue and was looking for an answer. In my case I had a typo in my files: matching pattern which caused it to not find the directory to watch and abort, although an error message would have been nice. I notice that in your sass task you prepend your files withassets/ but not in your watch task.

I understand you've likely moved on but hopefully this helps someone in the future.

like image 44
Kenjamin Avatar answered Feb 18 '23 10:02

Kenjamin