Grunt Compress without root folder Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Grunt Compress without root folder without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m trying to compress a directory using grunt. I have tried the following sections in my grunt file.

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

which gives me an empty zip file. Or

    compress: {
        main: {
            options: {
                archive: 'dist/output.zip',
                mode: 'zip'
            },
            files: [{
                src: ['build/*']
            }]
        }
    }

which gives me the following structure in my zip file

output.zip
 - build
   - my files

but I would like to remove the build directory to get

output.zip
 - my files

What changes can I make to get this structure?

Answer

Have you tried:

compress: {
    main: {
       options: {
           archive: 'dist/output.zip',
           mode: 'zip'
       },
       files: [{
           src: ['**/*'],
           cwd: 'build/',
           expand: true
       }]
    }
}
We are here to answer your question about Grunt Compress without root folder - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji