简体   繁体   中英

Unable to run Grunt tasks

I am facing a similar issue for most of my Grunt tasks while running.. Please help on this..

Add the command prompt commands, gruntFile.js and package.json file below

grunt copy --force

SyntaxError: Unexpected identifier Warning: Task "copy" not found. Used --force, continuing.

grunt uglify

SyntaxError: Unexpected identifier Warning: Task "uglify" not found. Use --force to continue.

GruntFile.js

'use strict';

module.exports = function (grunt) {

    // https://github.com/sindresorhus/load-grunt-tasks
    require('load-grunt-tasks')(grunt);

    // http://gruntjs.com/configuring-tasks#grunt-configuration
    grunt.initConfig({


        /* https://www.npmjs.com/package/grunt-contrib-jshint */
        /* http://jshint.com/docs/options/ */
        jshint: {
            options: {
                curly: true,
                eqeqeq: true,
                eqnull: true,
                browser: true,
                globals: {
                    jQuery: true
                },
            },

            user: ['app/js/**/*.js', '!app/js/jQuery.js'],

            gruntfile: {
                options: {
                    node: true
                },
                files: {
                    src: ['Gruntfile.js']
                }
            }
        },

               // https://www.npmjs.com/package/grunt-contrib-clean
        clean: {
            dist: {
                src: ['dist/']
            },
        },

        // https://www.npmjs.com/package/grunt-contrib-copy
        copy: {
            dist: {
                files: [{
                    expand: true,
                    cwd: 'app/',
                    src: ['js/**/*.js',
                        '**/*.html',
                        'css/**/*.css',
                    ],
                    dest: 'dist/'
                }]
            },
        },

        // https://www.npmjs.com/package/grunt-contrib-watch
        watch: {
            livereload: {
                files: ['app/**/*.html',
                    'app/js/**/*.js',
                    'app/css/**/*.css',
                    'app/images/**/*.{jpg,gif,svg,jpeg,png}'
                ],
                options: {
                    livereload: true
                }
            },

          },

        uglify: {
            combine: {
                files: {
                    'html/js/main.js': ['html/js/one.js']
                }
            }
        }


            });

    // Tasks to run

    // default task   > grunt
    grunt.registerTask('default', ['connect:app', 'watch']);


    // lint js    > grunt validate-js
    grunt.registerTask('validate-js', ['jshint']);

    //publish finished site to /dist directory  > grunt publish
    grunt.registerTask('publish', ['clean:dist', 'validate.js', 'copy:dist', 'imagemin', 'connect:dist']);

};

package.json

{
  "name": "Udacity-P",
  "description": "",
  "version": "0.0.1",
  "homepage": "",
  "author": {
    "name": "",
    "email": ""
  },
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-contrib-clean": "^0.6.0",
    "grunt-contrib-connect": "^0.11.2",
    "grunt-contrib-copy": "^0.8.1",
    "grunt-contrib-imagemin": "^0.9.4",
    "grunt-contrib-jshint": "^0.11.3",
    "grunt-contrib-watch": "^0.6.1",
    "grunt-responsive-images": "^0.1.6",
    "load-grunt-tasks": "^3.3.0"
  }
}

package.json ,您尚未下载uglify任务。

npm install grunt-contrib-uglify --save-dev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM