gpt4 book ai didi

javascript - Grunt 不加载外部任务

转载 作者:行者123 更新时间:2023-12-03 11:50:36 25 4
gpt4 key购买 nike

我遇到了困难,所以我希望这里有人可以帮助我解决这个问题...我正在组合一个新的 Grunt 堆栈,我可以在我的所有项目中使用它。但是,无论出于何种原因,它目前尚未加载任务。

这是我的 Gruntfile:

'use strict';

module.exports = function (grunt) {

var config = {
pkg: require('package.json')
};

// Load all grunt configuration options
grunt.util._.extend(config, loadConfig('./grunt/modules/'));

// Configure grunt
grunt.initConfig(config);

// Load and register all tasks from devDependencies
require('jit-grunt')(grunt);

// Load all custom tasks
grunt.loadTasks('grunt');

}

/**
* Load configuration files for Grunt
* @param {string} path Path to folder with tasks
* @return {object} All options
*
* http://thenittygritty.co/shared-grunt-configuration
*/
var loadConfig = function (path) {
var glob = require('glob');
var object = {};
var key;

glob.sync('*', { cwd: path }).forEach(function (option) {
key = option.replace(/\.js$/,'');
object[key] = require(path + option);
});

return object;
};

因此,我有一个“grunt”文件夹,其中包含我的所有自定义任务、别名任务和第 3 方任务。自定义和别名任务位于主文件夹中,而安装的第 3 方任务(cssmin.js、watch.js 等)位于“grunt/modules”文件夹中。

这是自定义和第三方的示例...

grunt/modules/connect.js:

'use strict';

// https://github.com/gruntjs/grunt-contrib-connect
module.exports = {

dev: {
options: {
port: 6000,
base: 'dist',
livereload: true
}
}

}

grunt/serve.js:

'use strict';

module.exports = function (grunt) {

grunt.registerTask(
'serve',
[
'build:dev',
'connect',
'watch'
]
);

}

但是,当我运行“gruntserve”(或其他任何内容)时,我收到任务未找到错误:

Loading "Gruntfile.js" tasks...ERROR
>> TypeError: undefined is not a function
Warning: Task "serve" not found. Use --force to continue.

Aborted due to warnings.

有什么想法吗?

最佳答案

这个问题实际上与我的 Gruntfile 没有任何关系...我的一项任务中存在一个问题,导致 Grunt 失败。一旦我解决了这个问题,一切就又开始工作了。

关于javascript - Grunt 不加载外部任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25857876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com