How can I configure a grunt closurecompiler task to output all js files in a directory to separate files

311 Views Asked by At

I am trying to use grunt-closurecompiler ( https://npmjs.org/package/grunt-closure-tools) to minify several directories full of javascript files. I want to minify the files using simple optimization for now, but I don't want them all concatenated into one file, I want one min.js file for each .js file in every directory. I'm trying to use this particular grunt package because it doesn't require any configuration and works out of the box. I am able to minify my files, but google closure always seems to generate one large file of output. I don't want to set these up as modules, so any tricks regarding using modules to do this won't work for me.

here's what I've tried in my package.json (note the commented out section - tried using expandmapping, which didn't seem to work either)

    closurecompiler: {
        minify: {

            files: [
                {
                    expand: true,     // Enable dynamic expansion.
                    cwd: 'lib/',      // Src matches are relative to this path.
                    src: ['*.js', '!*.min.js'],    // Actual pattern(s) to match.
                    dest: 'build/',   // Destination path prefix.
                    ext: '.min.js',   // Dest filepaths will have this extension.
                },
            ],

            //files: grunt.file.expandMapping(['lib/*.js'], 'build/', {
            //    rename: function (destBase, destPath) {
            //        return destBase + destPath.replace('.js', '.min.js');
            //    }
            //}),
            options: {
                // Any options supported by Closure Compiler, for example:
                "compilation_level": "SIMPLE_OPTIMIZATIONS",

                // Plus a simultaneous processes limit
                "max_processes": 5,

            }
        }
    },

any help would be greatly appreciated

-greg

0

There are 0 best solutions below