gmarty / grunt-closure-compiler

A Grunt task for Closure Compiler
MIT License
181 stars 48 forks source link

Enhancement: change compilation levels for certain files. #13

Open devinrhode2 opened 11 years ago

devinrhode2 commented 11 years ago

In trying to successfully use advanced compilation for a project but one of my dependencies flat out breaks when I use advanced compilation, and there's not much I can swiftly do about it. I can use advanced compilation on my stuff just fine, but need to use simple compilation for my other dependency.

Not an easy thing to do my any means, but I just wanted to write it down somewhere relevant.

devinrhode2 commented 11 years ago

Ok going to submit a PR for this... but first let's agree on an API:

I'm using advanced compilation, and only need one file compiled with the simple option, so this is the api I started writing:

grunt.initConfig({
  'closure-compiler': {
    frontend: {
      js: manifest.background.scripts,
      simple: ['node_modules/twitter-text/twitter-text.js'],
      jsOutputFile: 'compiled/background.cc.js',
      maxBuffer: 500,
      options: {
        'compilation_level': 'ADVANCED_OPTIMIZATIONS',
        'language_in': 'ECMASCRIPT5_STRICT',
        'externs': require('fs').readdirSync('./build/cc-externs')
      }
    }
  }
});

Now, I could see how someone would mostly use simple compilation and want advanced compilation for a few files where possible. So we could make an identical option to my simple

gmarty commented 11 years ago

To be honest, I prefer to keep this tool as simple as possible. What's great with Grunt is that you can actually automatize such tasks. What about compiling your code and dependencies apart and then merging together with another task? This is very easy to do with Grunt.

And of course, the other way would be to contribute advanced optimizations compatible versions of your dependencies.

devinrhode2 commented 11 years ago

How could I basically say...

grunt.runMoreStuff({
    'closure-compiler': {
      frontend: {
        js: manifest.background.scripts,
        jsOutputFile: 'compiled/background.cc.js',
        maxBuffer: 500,
        options: {
          'compilation_level': 'ADVANCED_OPTIMIZATIONS',
          'language_in': 'ECMASCRIPT5_STRICT'
        }
      }
    }
});

Any idea?

gmarty commented 11 years ago

You should probably do something like this:

grunt.initConfig({
  'closure-compiler': {
    advanced: {
      js: manifest.background.scripts,
      jsOutputFile: 'compiled/background.cc.js',
        options: {
          'compilation_level': 'ADVANCED_OPTIMIZATIONS'
        }
    },
    simple: {
      js: manifest.api.scripts,
      jsOutputFile: 'compiled/api.cc.js',
      options: {
          'compilation_level': 'SIMPLE_OPTIMIZATIONS'
      }
    },
  }
});

Then, find or develop a task to concatenate compiled/background.cc.js and compiled/api.cc.js.