Closed galenyuan closed 9 years ago
For example I have a project like this: -root ---folder1 -----jquery.js ---folder2 -----jquery.js It should create two zip files like this: -folder1.zip ---jquery.js -folder2.zip ---jquery.js
Any solution? Thanks so much.
Each task will only generate a single zip
file. You can dynamically configure grunt
to generate new tasks for the folders:
// Load in dependencies
var fs = require('fs');
var path = require('path');
module.exports = function (grunt) {
// Create a task for each folder
var zipConfig = {};
var folders = fs.readdirSync('root');
folders.forEach(function createZipTask (folder) {
// Save all folder contents to zip file (e.g. `root/folder1/*.*`)
var folderGlob = path.join('root', folder, '*.*');
var filename = folder + '.zip';
zipConfig[filename] = folderGlob;
});
// Save config to grunt
grunt.config.set('zip', zipConfig);
// Load in our grunt tasks
grunt.loadNpmTasks('grunt-zip');
};
Alternatively, you can create a task for each folder via hardcoding.
I want's to named .zip file with the name of folder, but can't find any method in doc, can you please help me to solve it? thanks!