- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试将现有的 Gruntfile 分成更小的文件,以便更轻松地进行概述。然而我遇到了一个颠簸。我正在使用 Bower.install 来安装我的项目依赖项。我的文件夹结构如下所示:
package.json
bower.json
config
--install.js
--default.js //Empty for now
gruntfile.js
我的 Gruntfile 现在看起来像这样:
'use strict';
module.exports = function(grunt) {
var npmDependencies = require('./package.json').devDependencies;
require('load-grunt-tasks')(grunt);
var configs = {
config : {
paths : {
"build" : ["grunts/*.js*", "package.json", "bower.json", "Gruntfile.js"],
}
}
};
var loadConfigs = require( 'load-grunt-configs' );
configs = loadConfigs( grunt, configs );
// Project configuration.
grunt.initConfig( configs );
}
我的 install.js 看起来像这样:
module.exports = function(grunt) {
var done = grunt.async();
var bower = require('bower').commands;
bower.install().on('end', function(data) {
done();
}).on('data', function(data) {
console.log(data);
}).on('error', function(err) {
console.error(err);
done();
});
}
但是这不起作用,因为我收到错误:
>> TypeError: Object #<Object> has no method 'async'
如果我删除所有异步困惑(我最终想保留),那么文件看起来会简单得多:
module.exports = function(grunt) {
var bower = require('bower').commands;
bower.install();
}
我仍然收到以下错误:
>> TypeError: Cannot call method 'hasOwnProperty' of undefined
我对这个主题相当陌生,到目前为止(所有内容都在一个文件中)它工作得很好。现在的大问题是:我如何回到那个点;)
最佳答案
install.js
有几个问题:
1) grunt对象没有公开异步函数,这是第一个错误的原因。 async函数可用于 grunt 任务,因此应该从任务内调用它。
2) 当 using node modules for configuration ,load-grunt-configs需要一个返回对象的函数,例如:
//config/jshint.js
module.exports = function(grunt, options){
return {
gruntfile : {
src : "Gruntfile.js"
}
}
}
在您的情况下,函数不返回任何内容,并且 load-grunt-configs 失败,并出现 Cannot call method 'hasOwnProperty' of undefined
错误。
以下应该有效:
module.exports = function(grunt) {
return grunt.registerTask("bower", function() {
var done = this.async();
var bower = require('bower').commands;
bower.install().on('end', function(data) {
done();
}).on('data', function(data) {
console.log(data);
}).on('error', function(err) {
console.error(err);
done();
});
});
}
关于javascript - 使用 grunt 加载 grunt-configs 和 Bower.install(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28138061/
我安装了 grunt 和 grunt cli,但仍然出现命令未找到错误 { "name": "angulartdd", "version": "1.0.0", "description":
我有一个使用“grunt-contrib-watch”和“grunt-exec”的 Grunt.js 文件,这是因为我想以一种独特的方式使用 handlebars 预编译器的一些自定义功能。 代码:
我正忙于尝试完成我正在运行的部署脚本。它可能有一半的时间有效,而且令人沮丧,因为我使用的大部分代码都不是我写的。我真的希望有一个我可以执行的较低级别的解决方法。 基本上发生的事情是我正在尝试执行 5
我想像在文档中定义的那样将参数传递给grunt-shell: module.exports = function(grunt) { // Configure Grunt grunt.initConfi
背景 我正在使用 Yeoman webapp 来搭建我的前端。 在 gruntfile 中,他们使用 grunt-rev 和 grunt-usemin Grunt-rev 将“修改”我的 Assets
我已经设置了grunt-eslint在我的 gruntfile.js 中,但是当我运行“grunt eslint”时,什么也没有发生。该任务看似即将开始,但 15 分钟后却停滞不前。 我的所有其他任务
我最近开始使用 grunt 做 JS 项目。 我有一个名为“grunt-contrib-jasmine”的插件用于 Jasmine 测试。我工作得很好,但我无法在浏览器中通过 specrunner 运
谁能告诉我这里做错了什么(我是 grunt 的新手)一个大学给我提供了一个基本的 gruntfile 设置 我已经安装了 node、js 和 grunt,但我不知道如何安装各种包(uglify、con
我正在尝试使用 grunt-contrib-watch和 grunt-rsync将任何文件更改上传到我的开发服务器。这是我的设置: var path = require('path'); module
尝试使用grunt-kill创建一个任务来终止我的 server-scorm 任务,并最终终止所有相关任务。这些说明非常短,因为它假设我知道有关 PID 文件的所有信息(我不知道,不是开发人员的错误)
我要么脑子一片空白,要么本该更复杂。 我正在尝试从 Grunt 任务运行 grunt-init,如下所示: grunt.registerTask('init', 'Scaffold various a
我有一个从玩家发射的射弹预制件,当它与“边界”碰撞时,它应该摧毁自己,当它击中“咕噜声”时,它应该摧毁自己和咕噜声。但是,当它碰到边界时,它会破坏自身和边界的对撞机。我创建了一个自定义标签脚本,允许我
module.exports = function(grunt){ grunt.initConfig({ pkg: grunt.file.readJSON('package.json'),
我已经加入了一个非营利性开源项目,想帮点忙,但我对 Grunt 不熟悉。我做了一些研究,但无法弄清楚为什么配置不起作用。 这是我正在尝试使用的插件。它允许应用多个后处理器,但我现在只需要 Autopr
下面的代码读取app/modules/中的每个子目录js的内容(例如app/modules/module1/js/, app/modules/module2/js/, aso.) 此脚本在不使用最后一
我正在尝试使用 grunt-exec 运行一个 javascript 测试运行程序,并传入一个已部署的链接变量。 我尝试通过使用 exec:setLink 设置环境变量 grunt.option('l
当我使用 grunt-contrib-watch 更改我的 js 文件时,我试图让 Grunt 重新加载它们。这是我的 Gruntfile: module.exports = function(gru
所以我的意思是: grunt.registerTask('default', ['default']); // CLI: grunt grunt.registerTask('serve', ['ser
我想创建一个通用的顶级 Gruntfile.js,配置为监视较少的文件更改。当less文件发生变化时,我想将其编译为css,然后在浏览器中实时加载css文件。我的功能正常,但我必须为每个项目复制 Gr
我正在使用 grunt-xmlpoke 更新 xml 文件。 xml 文件的路径作为参数提供。问题是文件部分中的第一个 WebConfigPath (键)被视为字符串。它更新了我的 xml 文件的本地
我是一名优秀的程序员,十分优秀!