Takazudolog

Takazudo's blog on GitHub

RSS Takazudo

grunt loadNpmTasks

| Comments

  • [ JavaScript ]
  • [ CoffeeScript ]
  • [ grunt ]
  • [ build ]

Basically, with grunt, you need to code your own tasks.
But you can also use tasks on npm. Here’s howto.

growl

Easy growling using grunt-growl.

module.exports = function(grunt){
  
  grunt.loadNpmTasks('grunt-growl');

  grunt.initConfig({
    growl: {
      test1: {
        message: 'OMG!!!',
        title: 'WOOOOT!!'
      }
    }
  });

  grunt.registerTask('default', 'growl');

};

CoffeeScript

Easy CoffeeScript compiling using grunt-coffee.
I want to be notified when the compiling successed, too.

module.exports = function(grunt){
  
  grunt.loadNpmTasks('grunt-growl');
  grunt.loadNpmTasks('grunt-coffee');

  grunt.initConfig({
    growl: {
      done: {
        title: 'grunt',
        message: 'SUCCESSED!!'
      }
    },
    coffee: {
      app: {
        src: [
          'coffee/1.coffee',
          'coffee/2.coffee'
        ],
        dest: 'js'
      }
    },
    watch: {
      app: {
        files: '<config:coffee.app.src>',
        tasks: 'coffee:app growl'
      }
    }
  });

  grunt.registerTask('default', 'coffee growl');

};

Sass

Sass compiling using grunt-sass.

module.exports = function(grunt){
  
  grunt.loadNpmTasks('grunt-growl');
  grunt.loadNpmTasks('grunt-sass');

  grunt.initConfig({
    growl: {
      done: {
        title: 'grunt',
        message: 'SUCCESSED!!'
      }
    },
    sass: {
      app: {
        src: 'scss/style.scss',
        dest: 'css/style.css'
      }
    },
    watch: {
      app: {
        files: 'scss/*',
        tasks: 'sass:app growl:done'
      }
    }
  });

  grunt.registerTask('default', 'sass growl:done');

};

Compass

Compiling compass scss files using grunt-compass.

module.exports = function(grunt){
  
  grunt.loadNpmTasks('grunt-growl');
  grunt.loadNpmTasks('grunt-compass');

  grunt.initConfig({
    growl: {
      done: {
        title: 'grunt',
        message: 'SUCCESSED!!'
      }
    },
    compass: {
      app: {
        src: 'scss/',
        dest: 'css/'
      }
    },
    watch: {
      app: {
        files: 'scss/*',
        tasks: 'compass:app growl:done'
      }
    }
  });

  grunt.registerTask('default', 'compass growl:done');

};

Notice

Before using there npm tasks, you need to do npm install grunt-coffee in the directory which grunt.js exists.

Npm tasks are mostly well coded. But you need to know that they are not always perfect. Report bugs or send pull request to authors if they didn’t work. Or you need to code tasks by yourself.

You can check my grunt examples on Takazudo/gruntExamples.
All examples here are in this repository too.

Comments