Here is my Gruntfile.js
module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON("package.json"), uglify: { options: { mangle: true } build: { src: "js/*.js", dest: "js/min/script.js" } } }); grunt.loadNpmTasks("grunt-contrib-uglify"); grunt.registerTask('default', [uglify]); };
Here is my package.json - I have run npm install
already, with all of the plugins that I will use in my Gruntfile, grunt-contrib-uglify is among them.
{ "name": "bootbuckle", "version": "0.1.0", "engines": { "node": ">= 0.10.0" }, "devDependencies": { "grunt": "~0.4.2", "grunt-contrib-watch": "~0.5.3", "grunt-contrib-sass": "~0.6.0", "grunt-csscomb": "~2.0.1", "grunt-contrib-htmlmin": "~0.1.3", "grunt-contrib-imagemin": "~0.4.1", "grunt-contrib-uglify": "~0.2.7" } }
When I simply run grunt
in the terminal - here is the error
build: { ^^^^^ Loading "Gruntfile.js" tasks...ERROR >> SyntaxError: Unexpected identifier Warning: Task "default" not found. Use --force to continue. Aborted due to warnings.
Thanks in advance for any help you may be able to provide.
EDIT Following Matti's guidance I have inserted a missing comma, a new error is now being thrown
Loading "Gruntfile.js" tasks...ERROR >> ReferenceError: uglify is not defined Warning: Task "default" not found. Use --force to continue. Aborted due to warnings.
Grunt is a JavaScript task runner, a tool used to automatically perform frequent tasks such as minification, compilation, unit testing, and linting. It uses a command-line interface to run custom tasks defined in a file (known as a Gruntfile). Grunt was created by Ben Alman and is written in Node.
The Gruntfile. js or Gruntfile. coffee file is a valid JavaScript or CoffeeScript file that belongs in the root directory of your project, next to the package. json file, and should be committed with your project source.
grunt. util. _ is deprecated and we highly encourage you to npm install lodash and var _ = require('lodash') to use lodash .
You missed a comma here:
uglify: { options: { mangle: true }, // <------- build: { src: "js/*.js", dest: "js/min/script.js" } }
Edit: as posted by japrescott, you have to define uglify task as string.
grunt.registerTask('default', ["uglify"]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With