首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有定义Grunt - pkg。

没有定义Grunt - pkg。
EN

Stack Overflow用户
提问于 2016-11-22 20:35:34
回答 1查看 1.1K关注 0票数 0

执行命令:默认任务是串联的。

代码语言:javascript
复制
grunt -v

我得到以下错误消息:

验证属性concat.dist存在于config...Warning中:在处理模板时发生错误(未定义pkg)。继续使用武力。

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

pkg.name in Gruntfile.js.

这里有什么问题?

Gruntfile.js节选:

代码语言:javascript
复制
 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

代码语言:javascript
复制
{
  "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"
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-22 20:43:26

我怀疑您的Gruntfile缺少一个在您的配置中设置pkg属性的部分。在大多数Gruntfile中,通常都会出现类似的情况。

代码语言:javascript
复制
grunt.initConfig({
  pkg: grunt.file.readJSON('package.json')
});

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40751123

复制
相关文章

相似问题

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