Prevent Google Closure Compiler from renaming settings objects

后端 未结 6 2045
礼貌的吻别
礼貌的吻别 2020-12-06 05:56

I\'m trying to get the Google Closure Compiler to not rename objects when passed as settings or data to a function. By looking at the annotations present in jQuery, I though

6条回答
  •  盖世英雄少女心
    2020-12-06 06:20

    Since your focus seems to be on the source rather than the output, it seems like what you're focused on is DRY (Don't Repeat Yourself). Here's an alternative DRY solution.

    You can run the Closure Compiler with --create_name_map_files. Doing so emits a file named _props_map.out. You can have your JSON-emitting server-side calls (ASP.Net MVC or whatever it might be) use these maps when emitting their JSON, so they're actually emitting minified JSON that leverages the renames the Closure Compiler performed. This way you can change the name of a variable or property on your Controller and your scripts, add more, etc, and the minification carries through from the scripts all the way back to the Controller output. All of your source, including the Controller, continues to be non-minified and easy to read.

提交回复
热议问题