【问题标题】:Grunt - pkg is not definedGrunt - pkg 未定义
【发布时间】:2016-11-22 20:35:34
【问题描述】:

执行命令: 默认任务是 concat。

grunt -v

我收到以下错误消息:

验证配置中存在 concat.dist 属性...警告:错误 处理模板时发生(未定义 pkg)。动武 继续。

我猜,pkg 是 package.json。 我使用占位符

pkg.name 在 Gruntfile.js 中。

这里有什么问题?

Gruntfile.js 摘录:

 concat: {
            options: {
                // define a string to put between each file in the concatenated output
                separator: ';'
            },
            dist: {
                // the files to concatenate
                src: ['www/**/*.js'],
                // the location of the resulting JS file
                dest: 'www-built/<%= pkg.name %>.js'
            }
        }

package.json

{
  "name": "myprodpackage",
  "version": "0.0.9",
  "devDependencies": {
    "grunt": "^1.0.1",
    "grunt-contrib-concat": "^1.0.1",
    "grunt-contrib-cssmin": "^1.0.2",
    "grunt-contrib-jshint": "^1.0.0",
    "grunt-contrib-qunit": "^1.2.0",
    "grunt-contrib-uglify": "^2.0.0",
    "grunt-contrib-watch": "^1.0.0"
  },
  "description": "test package",
  "main": "Gruntfile.js",
  "dependencies": {
    "bloodhound": "^1.0.0",
    "backbone": "^1.3.3",
    "grunt-contrib-cssmin": "^1.0.2",
    "grunt-contrib-concat": "^1.0.1",
    "grunt-contrib-qunit": "^1.2.0",
    "grunt": "^1.0.1",
    "grunt-contrib-uglify": "^2.0.0",
    "gulp-clean-css": "^2.0.13",
    "grunt-contrib-jshint": "^1.0.0",
    "grunt-contrib-watch": "^1.0.0",
    "lodash": "^4.17.2",
    "gulp-minify": "^0.0.14",
    "gulp-uglify": "^2.0.0",
    "jquery": "^3.1.1",
    "requirejs": "^2.3.2",
    "respond.js": "^1.4.2",
    "text": "^2.0.15",
    "underscore": "^1.8.3"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "legends",
  "license": "ISC"
}

【问题讨论】:

    标签: javascript node.js asp.net-mvc gruntjs grunt-contrib-concat


    【解决方案1】:

    我怀疑您的 Gruntfile 缺少在您的配置中设置 pkg 属性的部分。在大多数 Gruntfile 中都可以找到类似的内容。

    grunt.initConfig({
      pkg: grunt.file.readJSON('package.json')
    });
    

    添加该属性应使pkg.name 与您的package.json 中的相同。

    【讨论】:

      猜你喜欢
      • 2013-12-13
      • 1970-01-01
      • 1970-01-01
      • 2015-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      相关资源
      最近更新 更多