I've created a new grunt task and within it I want to use grunt-contrib-concat to concatenate a few files together.
我创建了一个新的繁重的任务,在这个任务中,我想使用grunt- managed -concat将几个文件连接在一起。
I looked through the docs but I don't find anything that hinted at being able to do this. It seems like a trivial use case, so I'm probably just over looking something.
我浏览了一下文档,但我没有发现任何暗示能够做到这一点的东西。这似乎是一个微不足道的用例,所以我可能只是在寻找一些东西。
Update 1:
更新1:
I also want to be able to configure this task from within my custom task.
我还希望能够在自定义任务中配置此任务。
For example, I create a list of files in my custom task. After I have that list, I want to pass them to the concat task. How can I do that?
例如,我在自定义任务中创建一个文件列表。在我有了这个列表之后,我想把它们传递给concat任务。我该怎么做呢?
I would like to be able to do something like this.
我想做这样的事情。
grunt.task.run('concat', { src: ['file1','file2'], dest: 'out.js'})
Update 2:
更新2:
To achieve what I want, I have to manually configure the grunt task. Here's an example that showed me what I wanted.
为了实现我想要的,我必须手动配置grunt任务。这里有个例子告诉我我想要什么。
https://github.com/gruntjs/grunt-contrib/issues/118#issuecomment-8482130
https://github.com/gruntjs/grunt-contrib/issues/118 # issuecomment - 8482130
4 个解决方案
#1
34
Here's an example of manually configuring a task within a task and then running it.
这里有一个在任务中手动配置任务并运行它的示例。
https://github.com/gruntjs/grunt-contrib/issues/118#issuecomment-8482130
https://github.com/gruntjs/grunt-contrib/issues/118 # issuecomment - 8482130
grunt.registerMultiTask('multicss', 'Minify CSS files in a folder', function() {
var count = 0;
grunt.file.expandFiles(this.data).forEach(function(file) {
var property = 'mincss.css'+count+'.files';
var value = {};
value[file] = file;
grunt.config(property, value);
grunt.log.writeln("Minifying CSS "+file);
count++;
});
grunt.task.run('mincss');
});
#2
26
From https://github.com/gruntjs/grunt/wiki/Creating-tasks
从https://github.com/gruntjs/grunt/wiki/Creating-tasks
grunt.registerTask('foo', 'My "foo" task.', function() {
// Enqueue "bar" and "baz" tasks, to run after "foo" finishes, in-order.
grunt.task.run('bar', 'baz');
// Or:
grunt.task.run(['bar', 'baz']);
});
#3
10
Thx to Arron that pointed us out in the right direction to his own question. The grunt.config is the key from the example above. This task will override the src property of the browserify task
Thx对Arron说,这给我们指出了他自己问题的正确方向。咕哝。配置是上面例子中的关键。此任务将覆盖browserify任务的src属性。
Task definition:
任务定义:
grunt.registerTask('tests', function (spec) {
if (spec) {
grunt.config('browserify.tests.src', spec);
}
grunt.task.run(['jshint', 'browserify:tests', 'jasmine']);
});
Task call:
任务调用:
grunt tests
or
或
grunt tests:somewhere/specPath.js
#4
0
If you are feeling lazy I ended up publishing a npm module that forwards the configs from your task into the subtask that you want to run:
如果您感到懒惰,我最终发布了一个npm模块,它将configs从您的任务转发到您想要运行的子任务:
https://www.npmjs.org/package/extend-grunt-plugin
https://www.npmjs.org/package/extend-grunt-plugin
#1
34
Here's an example of manually configuring a task within a task and then running it.
这里有一个在任务中手动配置任务并运行它的示例。
https://github.com/gruntjs/grunt-contrib/issues/118#issuecomment-8482130
https://github.com/gruntjs/grunt-contrib/issues/118 # issuecomment - 8482130
grunt.registerMultiTask('multicss', 'Minify CSS files in a folder', function() {
var count = 0;
grunt.file.expandFiles(this.data).forEach(function(file) {
var property = 'mincss.css'+count+'.files';
var value = {};
value[file] = file;
grunt.config(property, value);
grunt.log.writeln("Minifying CSS "+file);
count++;
});
grunt.task.run('mincss');
});
#2
26
From https://github.com/gruntjs/grunt/wiki/Creating-tasks
从https://github.com/gruntjs/grunt/wiki/Creating-tasks
grunt.registerTask('foo', 'My "foo" task.', function() {
// Enqueue "bar" and "baz" tasks, to run after "foo" finishes, in-order.
grunt.task.run('bar', 'baz');
// Or:
grunt.task.run(['bar', 'baz']);
});
#3
10
Thx to Arron that pointed us out in the right direction to his own question. The grunt.config is the key from the example above. This task will override the src property of the browserify task
Thx对Arron说,这给我们指出了他自己问题的正确方向。咕哝。配置是上面例子中的关键。此任务将覆盖browserify任务的src属性。
Task definition:
任务定义:
grunt.registerTask('tests', function (spec) {
if (spec) {
grunt.config('browserify.tests.src', spec);
}
grunt.task.run(['jshint', 'browserify:tests', 'jasmine']);
});
Task call:
任务调用:
grunt tests
or
或
grunt tests:somewhere/specPath.js
#4
0
If you are feeling lazy I ended up publishing a npm module that forwards the configs from your task into the subtask that you want to run:
如果您感到懒惰,我最终发布了一个npm模块,它将configs从您的任务转发到您想要运行的子任务:
https://www.npmjs.org/package/extend-grunt-plugin
https://www.npmjs.org/package/extend-grunt-plugin