javascript - 如何创建引用其他 grunt 任务的 grunt 任务

标签 javascript node.js gruntjs

我有一个 grunt 文件,我正在使用它来构建我的网络应用程序。

这个 grunt 文件使用了几个 grunt contrib 插件,比如 cleancopycompasscssmin 等来正确构建网络应用。

这个 grunt 文件还应该处理生成 CSS 和复制文件以创建主题 CSS 文件。目前,我正在为每个主题的 cleancopycompass(等)任务添加目标。

这在 grunt 文件中变得笨拙,并且在添加新主题时会变得困难且容易出错。

为了让事情变得更简单,我真的很想创建我自己的自定义“主题”grunt 任务,它将在内部使用其他 grunt contrib 任务( cleancopycompass 等)来执行指定主题的所有必要任务。

只要主题的少量配置数据(主要是它的源文件夹),我就有足够的信息来调用其他任务(因为主题源文件和目标文件是非常约定驱动的)。

我似乎无法找到一种方法来从我的自定义任务中调用任务,我可以在自定义任务中调用任务并以编程方式指定所有配置选项、文件等。

有人知道我该怎么做吗?

谢谢,埃德

最佳答案

I can't seem to find a way to call a task from within my custom task where I can do it and specify all of the config options, files, etc. programmatically.

我认为您不能使用特定配置运行 grunt 多任务,因为多任务配置是从任务配置中指定的目标读取的。

因此,一种方法是在运行之前修改任务配置。

这是一个非常基本的例子:

grunt.registerMultiTask('theme', function() {
    var themeName = this.options().name;
    grunt.config.set('yourOtherTask.dist.options.name', themeName);
    grunt.task.run('yourOtherTask');
});

关于javascript - 如何创建引用其他 grunt 任务的 grunt 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18456298/

相关文章:

node.js - Nodejs Expressjs Cluster 集群 app.js 的正确方法

javascript - Grunt connect-modrewrite 不起作用

javascript - UglifyJS 压缩

javascript - NodeJS 包依赖

javascript - node.js - 重载函数

node.js - Grunt Bower jquery.min.map 错误。设置我的第一个 MEAN 应用程序

javascript - 如何在 Angularjs Protractor 中使用命令行参数?

javascript - three.js:如何让透明的png Sprite 转换和接收阴影?

javascript - 将对象数组转换为包含对象数组的对象(复杂)

javascript - 如何使用 ExtJs 制作一个 100% 高度和宽度的窗口?