user3240114
user3240114

Reputation: 123

Grunt won't find any tasks

Im fairly new to the whole "front end workflow" stuff, and im trying to learn how to use grunt, and ive set up a task to minify my css but Grunt wont find any tasks whatsoever

this is my grunt file

module.exports = function(grunt) {

grunt.initConfig({

        pkg: grunt.file.readJSON('package.json'),
        min:{
            dist:{
                src: 'public/stylesheets/*.css',
                dest: 'public/stylesheets/builds'
            }
        }
    });

    grunt.registerTask('default', ['min']);
}

minify is installed globally and in the project

ive tried running the default

grunt

and

grunt min

minify is in my package.json as

"minify": "~0.6.1",

Upvotes: 0

Views: 648

Answers (1)

Matthew Bakaitis
Matthew Bakaitis

Reputation: 11970

Several potential issues here, all of which are likely causing the issues.


Problem: You are using minify which isn't a grunt plugin.

Solutions: npm install grunt-contrib-uglify and/or grunt-contrib-cssmin as makes sense for your needs.


Problem: You aren't loading any plugins/tasks...at least not in the code you posted.

Solution: Load tasks with grunt.loadNpmTasks before you register tasks. For example, if you use uglify and cssmin, you would need these lines before grunt.registerTask:

grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');

Possible complete solution for this specific issue

1) npm install grunt-contrib-uglify

2) npm install grunt-contrib-cssmin

3) Update your gruntfile to resemble this.

You will need to edit the directories to match your project specifics...this is almost guaranteed to fail if you don't edit it first. See the docs for grunt-contrib-uglify or -cssmin for full details on options, paths, etc...:

module.exports = function(grunt) {

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify: {
      dist: {
        files: {
          'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
        }
      }
    },
    cssmin: {
      minify: {
        expand: true,
        cwd: 'release/css/',
        src: ['*.css', '!*.min.css'],
        dest: 'release/css/',
        ext: '.min.css'
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-cssmin');

  grunt.registerTask('default', ['uglify', 'cssmin']);

};

Upvotes: 1

Related Questions