thanpolas / grunt-closure-tools

Google Closure Tools for grunt
MIT License
95 stars 22 forks source link

New option in `compilerOpts` - `useGoogExport: true` #33

Closed vogdb closed 11 years ago

vogdb commented 11 years ago

When I use google-closure I often use goog.exportSymbol and goog.exportProperty functions. I am quite tired to drag their sources from one project to another. So I want to propose a new option in compilerOpts - useGoogExport: true. When it is enabled you can use these export methods in your project without adding their sources. Compiler automatically will use their definitions when generating minified project sources. If something like this already exists let me know because I couldn't find it in the docs. If not I will be glad to implement it.

thanpolas commented 11 years ago

When it is enabled you can use these export methods in your project without adding their sources.

Can you elaborate a bit more how this will happen? Can you provide an example?

I am also using these funcs, i don't understand the need to transport them...

vogdb commented 11 years ago

For example I have projects A and B. In both of them I use these export methods. To do that I add to both projects next source:

goog.isDef = function (val) {...}
goog.exportPath_ = function (name, opt_object, opt_objectToExportTo) {...}
goog.exportSymbol = function (publicPath, object, opt_objectToExportTo) {...};
goog.exportProperty = function (object, publicName, symbol) {...};

Let's call it GoogExport. GoogExport by the way is a part of base.js. Now I need to add GoogExport in every closureCompiler target in both projects A and B. So we have repeated GoogExport in A and B. Also we have repeated link to it in every closureCompiler target of A and B.

closureCompiler: {
  options: {
  },
  min1: {
    src: ['GoogExport.js', 'src1.js'],
    dest: 'src1.min.js'
  },
  min2: {
    src: ['GoogExport.js', 'src2.js'],
    dest: 'src2.min.js'
  }
}

Instead of that I propose to move GoogExport to the grunt-closure-tools and use property useGoogExport: true everytime we want to use export methods in closureCompiler. When libCompiler.js find useGoogExport: true it will add path to GoogExport as another --js to cmd.

closureCompiler: {
  options: {
     useGoogExport: true
  },
  min1: {
    src: ['src1.js'],
    dest: 'src1.min.js'
  },
  min2: {
    src: ['src2.js'],
    dest: 'src2.min.js'
  }
}
thanpolas commented 11 years ago

the useGoogExport option is very ad-hoc, i can imagine that you would also need googExportPath to cover all the basis.

I am not very sold for this... i find having to type:

  options: {
     useGoogExport: true
  },

... more work than just adding the Goog exports file GoogExport.js. I don't see a win here...

I am using similar patterns, including parts of the goog.base runtime in very small libraries that later get CCed...

vogdb commented 11 years ago

Ok, then I close the issue. What does 'CCed...' means? Closure compiled?

thanpolas commented 11 years ago

yep, closure compiled