How can I run a task in Grunt using an array of filenames which are dynamically generated?

∥☆過路亽.° 提交于 2019-12-14 04:20:23

问题


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?

Any help much appreciated.


回答1:


You can use a variable to construct the config passed initConfig:

var deleteFilenames = ["foo", "bar", "baz"];
grunt.initConfig({
    clean: deleteFilenames
});

In the code above, the list is static but deleteFilenames could be constructed from an algorithm that computes file names.




回答2:


You can try using a wildcard token:

clean: ["file*"]

If you want something cleaner, you should include your Gruntfile.js or try to ouput your generated assets into a specific directory (such as dist/).



来源:https://stackoverflow.com/questions/22270567/how-can-i-run-a-task-in-grunt-using-an-array-of-filenames-which-are-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!