javascript 如何在 grunt 中压缩文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13847432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 19:57:09  来源:igfitidea点击:

How can I zip a folder in grunt?

javascriptnode.jsgruntjs

提问by Anshul

I have a folder "foo", but in my target folder "target"I want to send zip version of my "foo"folder such as "foo.zip", I google and found many way for zipping files but not for folder, so how can we zip a whole folder in grunt ?

我有一个文件夹"foo",但在我的目标文件夹中,"target"我想发送我的"foo"文件夹的zip 版本,例如"foo.zip",我在谷歌上搜索并找到了很多压缩文件的方法,但没有找到压缩文件夹的方法,那么我们如何在 grunt 中压缩整个文件夹?

回答by

The accepted answer was throwing an error in grunt-contrib-compress 0.5.0. Try this instead:

接受的答案是在 grunt-contrib-compress 0.5.0 中引发错误。试试这个:

compress: {
    foo: {
        options: {
            archive: './foo.zip',
            mode: 'zip'
        },
        files: [
            { src: './foo/**' }
        ]
    }
}

回答by Anshul

From above suggestion I am able to get my answer,We can use https://github.com/gruntjs/grunt-contrib-compress/for zipping a folder.

从上面的建议我可以得到我的答案,我们可以使用https://github.com/gruntjs/grunt-contrib-compress/压缩文件夹。

compress: {
            zip:{ 
                  files: {
                            './foo.zip': './foo/**'
                         }
                }
          }