简体   繁体   English

使用grunt-contrib-compress将内容压缩到归档根目录

[英]Compress content to the archive root using grunt-contrib-compress

I have the following directory structure, and I want to zip the content of dev folder and place it in the root of the generated archive without it being wrapped inside a top level folder: 我有以下目录结构,我想压缩dev文件夹的内容并将其放在生成的存档的根目录中,而不是将其包装在顶级文件夹中:

_build/    #build scripts
dist/      #destination
dev/       #source

Here is the code (gruntfile.js inside _build): 这是代码(_build中的gruntfile.js):

    compress: {             
         main : {
            options : {
                archive : "../dist/dev.zip"
            },
            files : [
                { expand: true, src : "../dev/**/*" }
            ]
        }     
      }

I wish I could zip only the contents of dev folder and place it into dist folder. 我希望我只能压缩开发文件夹的内容并将其放入dist文件夹。 But when I try to do so I, all the content of dev are zipped inside a root folder. 但是当我尝试这样做时,dev的所有内容都压缩在根文件夹中。

Actual generated zip: 实际生成的zip:

dist/
   |____ dev.zip
          |_____ dev/
                  |_____ index.html
                  |_____ styles/style.css

But I want the zip file to be like this: 但我希望zip文件是这样的:

dist/
   |____ dev.zip
        |_____ index.html
        |_____ styles/style.css

You see? 你看? the files are being wrapped in a folder(with the same name as the zip) instead of being place into the root of zip file. 文件被包装在一个文件夹中(与zip同名),而不是放在zip文件的根目录中。

Can this be achieved in some way? 这可以通过某种方式实现吗?

Thank you 谢谢

you can do as exposed here : https://github.com/gruntjs/grunt-contrib-compress/issues/33 你可以在这里公开: https//github.com/gruntjs/grunt-contrib-compress/issues/33

For example : 例如 :

compress : {
  main : {
    options : {
      archive : "myapp.zip"
    },
    files : [
      { expand: true, src : "**/*", cwd : "dist/" }
    ]
  }
}

will generate myapp.zip in the root path, countaining all files and directory included in /dist, but not the dist directory itself. 将在根路径中生成myapp.zip,计算/ dist中包含的所有文件和目录,但不包括dist目录本身。

another example, more in line with original question: 另一个例子,更符合原始问题:

    compress: {
    main: {
        options: {
            archive : "../dist/dev.zip"
        },
        files: [
            {
                expand: true,
                cwd: '../dev/',
                src: ['**'],
            }
        ]
    },
},

This should give your flat structure: 这应该给你的扁平结构:

 dist/
   |____ dev.zip
        |_____ index.html
        |_____ styles/style.css

checkout this great article on grunt-compress: http://www.charlestonsw.com/what-i-learned-about-grunt-compress/ 结帐这篇关于grunt-compress的好文章: http//www.charlestonsw.com/what-i-learned-about-grunt-compress/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM