Nikos
Nikos

Reputation: 7552

How get grunt-closure-compiler to apply minimization to each file separately in a directory

Is there a way I can get grunt-closure-compiler to apply minimization to each file separately in a directory (overriding the original) instead of producing a single file as the output. If I can't override the original I am happy to place output files in a separate output directory.

https://github.com/gmarty/grunt-closure-compiler

Normally the procedue would be like this producing a single file:

grunt.initConfig({
  'closure-compiler': {
    frontend: {
      closurePath: '/src/to/closure-compiler',
      js: 'static/src/frontend.js',
      jsOutputFile: 'static/js/frontend.min.js',
      maxBuffer: 500,
      options: {
        compilation_level: 'ADVANCED_OPTIMIZATIONS',
        language_in: 'ECMASCRIPT5_STRICT'
      }
    }
  }
});

Upvotes: 0

Views: 207

Answers (2)

Digital-Clouds
Digital-Clouds

Reputation: 552

As the other answer suggests, you need the modules option. However grunt-closure-compiler doesn't actually support this.

There's a fork of it which supports modules. It doesn't use the standard grunt file config so you can't use globbing patterns to get it to take all of the files in a folder. I've gotten around this by writing a grunt task to create the modules object and pass it into the config for the closure-compiler task.

Upvotes: 0

burnttoast11
burnttoast11

Reputation: 1184

You can use the module option of the Closure Compiler to produce multiple output files. You would have to list each JavaScript file as its own module, so if you have many JavaScript files this could be pretty tedious.

The module option is not very well documented, but see the posts below to see how it works:

Upvotes: 0

Related Questions