无法运行Grunt任务

时间:2016-05-23 10:18:39

标签: javascript angularjs node.js gruntjs

我在运行时遇到了大部分Grunt任务的类似问题..请帮忙...

下面添加命令提示符命令,gruntFile.js和package.json文件
  
    

grunt copy --force

         
      

SyntaxError:意外的标识符警告:找不到任务“copy”。使用--force,继续。

    
         

grunt uglify

         
      

SyntaxError:意外的标识符警告:找不到任务“uglify”。使用--force继续。

    
  
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"
  }
}

1 个答案:

答案 0 :(得分:0)

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

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