prostyash
prostyash

Reputation: 117

Cant find a solution for error "Warning: Task "uglify" not found"

Here is my gruntfile.js:

module.exports = function(grunt) {

  require('load-grunt-tasks')(grunt);

  grunt.initConfig({

    uglify: {
      start: {
        files: {
          'js/script.min.js': ['js/script.js'],
        }
      }
    },

    imagemin: {
      build: {
        options: {
          optimizationLevel: 3
        },
        files: [{
          expand: true,
          src: ['img/sprite_svg/*.svg'],
        }]
      }
    },

    svgstore: {
      options: {
        includeTitleElement: false,
        svg: {
          style: 'display:none',
        },
        cleanup: [
          'fill',
        ],
      },
      default : {
        files: {
          'img/sprite.svg': ['img/sprite_svg/*.svg'],
        },
      },
    },

    watch: {
      livereload: {
        options: { livereload: true },
        files: ['build/**/*'],
      },
      scripts: {
        files: ['js/script.js'],
        tasks: ['js'],
        options: {
          spawn: false
        },
      },
      images: {
        files: [
          'img/sprite_svg/*.svg'
        ],
        tasks: ['img'],
        options: {
          spawn: false
        },
      },
      html: {
        files: ['./index.html'],
        // tasks: ['html'],
        options: {
          spawn: false
        },
      },
    },

    browserSync: {
      dev: {
        bsFiles: {
          src : [
            'img/sprite.svg',
            './index.html',
          ]
        },
        options: {
          watchTask: true,
          server: {
            baseDir: "./",
          },
          startPath: "index.html",
          ghostMode: {
            clicks: true,
            forms: true,
            scroll: false
          }
        }
      }
    }

  });

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

  grunt.registerTask('default', [
    'js',
    'img',
    'browserSync',
    'watch'
  ]);

  grunt.registerTask('js', [
    'uglify'
  ]);

  grunt.registerTask('img', [
    'imagemin',
    'svgstore'
  ]);

};

I have already install uglify and imagemin npm packages but i still gеt error : Warning: Task "uglify" not found"

This was working until I added the svgstore, and I think it might be a syntax error. However this is the first time I have used this and I simply don't know what is causing the problem. Any help would be greatly appreciated.

Upvotes: 1

Views: 391

Answers (2)

kjonach
kjonach

Reputation: 154

What is in your package.json file?

"load-grunt-tasks" reads from "dependencies" and "devDependencies" in package.json so you don't have to invoke "grunt.loadNpmTasks".

Also, you should be installing "grunt-contrib-uglify" not "uglify".

Upvotes: 1

Mike Sheehan
Mike Sheehan

Reputation: 530

You have extra commas after the last item in two arrays

grunt.registerTask('js', [
  'uglify', // <-- remove this comma 
]);

grunt.registerTask('img', [
  'imagemin',
  'svgstore', // <-- remove this comma too
]);

Upvotes: 0

Related Questions