最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Compress content to the archive root using grunt-contrib-compress - Stack Overflow

programmeradmin6浏览0评论

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:

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

Here is the code (gruntfile.js inside _build):

    press: {             
         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. But when I try to do so I, all the content of dev are zipped inside a root folder.

Actual generated zip:

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

But I want the zip file to be like this:

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.

Can this be achieved in some way?

Thank you

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:

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

Here is the code (gruntfile.js inside _build):

    press: {             
         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. But when I try to do so I, all the content of dev are zipped inside a root folder.

Actual generated zip:

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

But I want the zip file to be like this:

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.

Can this be achieved in some way?

Thank you

Share Improve this question asked Jul 12, 2013 at 14:17 DaviBenNunDaviBenNun 731 gold badge3 silver badges6 bronze badges 1
  • Hi Davi, I'm facing the same problem, did you find a solution? – Q_Mlilo Commented Jul 17, 2013 at 8:05
Add a ment  | 

2 Answers 2

Reset to default 11

you can do as exposed here : https://github./gruntjs/grunt-contrib-press/issues/33

For example :

press : {
  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.

another example, more in line with original question:

    press: {
    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-press: http://www.charlestonsw./what-i-learned-about-grunt-press/

发布评论

评论列表(0)

  1. 暂无评论