5

I'm new to Node.js and Grunt... I'm attempting to use Node.js and Grunt on a Windows server to watch my main.less file and do a standard compile and concatinate. I'm able to do this while the command prompt is open, but I need this to run as a daemon while not logged into the server since the .less files get deployed from our CMS that sits in the cloud.

I found promising documentation in Grunt-Forever, but it requires you to point to an application, while I just want to perform the grunt watch task.

Someone else asked a similar question 9 months ago, but nobody gave an answer: Grunt.js Watch Forever

I tried this from the command line:

FWIW, you can do forever /usr/local/bin/grunt --base . watch to use forever with grunt watch atm.

But, I got errors.

Here is my gruntfile:

module.exports = function(grunt) {

  grunt.registerTask('watch', [ 'watch' ]);

  grunt.initConfig({
    concat: {
      js: {
        src: [
          'js/global.js','js/googlemap.js'
        ],
        dest: 'js/main.min.js'
      },
    },
    uglify: {
      options: {
        mangle: false
      },
      js: {
        files: {
          'js/main.min.js': ['js/main.min.js']
        }
      }
    },
    less: {
      style: {
        files: {
          "css/style.css": "less/main.less"
        }
      }
    },
    watch: {
      js: {
        files: ['js/global.js','js/googlemap.js'],
        tasks: ['concat:js', 'uglify:js']
      },
      css: {
        files: ['less/*.less'],
        tasks: ['less:style']
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-less');
  grunt.loadNpmTasks('grunt-contrib-watch');

};

Any help is much appreciated!

Community
  • 1
  • 1
Bullfrog
  • 51
  • 1

2 Answers2

1

Use node to call grunt, use PM2 to run and manage node.

wilbeibi
  • 3,403
  • 4
  • 25
  • 44
0

Try running the grunt watch task with nohup. Since you mentioned "Windows server" you can check this answer about nohup equivalent in Windows. Then you will have the grunt task running even when you log out of the server.

Community
  • 1
  • 1
Lachezar
  • 6,523
  • 3
  • 33
  • 34