我如何运行使用的是动态生成的文件名数组咕噜任务? [英] How can I run a task in Grunt using an array of filenames which are dynamically generated?
问题描述
我是相当新的使用步兵,但有任务如何安装并运行一个相当不错的理解。到目前为止,我能为我想,其中包括缩小JS,复制文件并运行jshint运行一切。
I am fairly new to using Grunt but have a fairly good understanding of how tasks are installed and run. So far I am able to run everything as I want which includes minifying js, copying files and running jshint.
我现在要运行干净从文件夹中,但只有我希望能动态生成所选文件的数组中删除文件。
I now want to run 'clean' to remove files from a folder but only an array of selected files which I hope to generate dynamically.
所以,如果我有一个动态生成阵列例如
So if I had a dynamically generated array e.g.
var deleteFilenames = ["file3.js","file2.jpg","file7.html"] etc.
我将如何设置一个咕噜干净的任务只是删除这些文件?
How would I set a grunt clean task to just delete these files?
任何帮助非常AP preciated。
Any help much appreciated.
推荐答案
您可以使用一个变量来构造通过配置 initConfig
:
You can use a variable to construct the config passed initConfig
:
var deleteFilenames = ["foo", "bar", "baz"];
grunt.initConfig({
clean: deleteFilenames
});
在上面的code,列表是静态的,而是 deleteFilenames
可以从计算文件名的算法构造。
In the code above, the list is static but deleteFilenames
could be constructed from an algorithm that computes file names.
这篇关于我如何运行使用的是动态生成的文件名数组咕噜任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!