简体   繁体   中英

Google Closure Compiler ADVANCED_OPTIMIZATIONS - Exclude All function names

I'm using Google's Closure Compiler to reduce the size of my Java Script code. Unfortunately the Closure Compiler does also change ALL function names in the Advanced mode without an easy option to change that.

I do need to exclude functions that are defined as properties (eg car.bla = function() ) completely. This includes the ones that I use and that are not defined at all in the local code, and the ones that I define myself.

I know that there is externs and exports (although I don't fully understand them) but I do not want to have to keep maintaining any extra files beside my code.

I would also be find to exclude any functions (also non-property functions).

After googling for a few hours I've still not found an options for that.

There are a few answers here;

  1. Use @export to label a property as "used by external sources", such as an Angular binding.
  2. Create an externs . These are used when you have code that is compiled separately from your code, but they need to interact. Have a look at how simple Angular's externs are.
  3. Reduce your compilation level to WHITESPACE_ONLY
  4. Depending on your setup, you may be able to pass --property_renaming=ALL_UNQUOTED and use foo['bar'] to access foo.bar
  5. Depending on your setup, you may be able to Pass --property_renaming=OFF

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM