diff --git a/Gruntfile.js b/Gruntfile.js index 8faafc4..6218952 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -165,6 +165,21 @@ module.exports = function (grunt) { }, src: 'test/fixture/index-external.html', dest: 'test/generated/index-external.html' + }, + 'test-multiple-files-folder': { + options: { + base: 'test/fixture', + minify: true, + width: 1300, + height: 900, + css: [ + 'test/fixture/styles/main.css', + 'test/fixture/styles/bootstrap.css' + ], + }, + files: [ + {expand: true, cwd: 'test/fixture/multiple', src: ['*.html'], dest: 'test/generated/multiple-files-folder'} + ] } } }); diff --git a/tasks/critical.js b/tasks/critical.js index 2232548..457d84e 100644 --- a/tasks/critical.js +++ b/tasks/critical.js @@ -55,14 +55,24 @@ module.exports = function (grunt) { async.eachSeries(srcFiles,function(src,cb){ var opts = extend({},options); opts.src = path.resolve(src).replace(basereplace,''); + + // check if the destination is a folder and not a file + var destination; + if (grunt.file.isDir(f.dest)) { + + destination = path.join(f.dest, src); + } else { + destination = f.dest; + } + try { critical[command](opts, function (err, output){ if (err) { return cb(err); } - grunt.file.write(f.dest, output); + grunt.file.write(destination, output); // Print a success message. - grunt.log.ok('File "' + f.dest + '" created.'); + grunt.log.ok('File "' + destination + '" created.'); cb(null,output); });