首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Gruntfile.js -未找到任务"default“

Gruntfile.js -未找到任务"default“
EN

Stack Overflow用户
提问于 2014-01-11 20:43:07
回答 2查看 42.5K关注 0票数 23

这是我的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]);

};

这是我的package.json -我已经运行了npm install,我将在我的grunt文件中使用所有的插件,grunt-contrib plugins就是其中之一。

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

当我简单地在终端中运行grunt时--下面是错误

  build: {
  ^^^^^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected identifier
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.

提前感谢您所能提供的任何帮助。

按照Matti的指导编辑我插入了一个缺少的逗号,现在抛出了一个新的错误

Loading "Gruntfile.js" tasks...ERROR
>> ReferenceError: uglify is not defined
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-01-11 20:46:16

您在这里漏掉了一个逗号:

    uglify: {
      options: {
        mangle: true
      }, // <-------
      build: {
        src: "js/*.js",
        dest: "js/min/script.js"
      }
    }

编辑:正如japrescott发布的,你必须将uglify任务定义为字符串。

grunt.registerTask('default', ["uglify"]);
票数 32
EN

Stack Overflow用户

发布于 2014-01-11 20:45:36

像这样试一下

  grunt.registerTask('default', ["uglify"]);
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21062362

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档