In GWT 2.0 CssResource, how I can turn off obfuscation for all my css classes?

心已入冬 提交于 2019-12-03 10:47:01

According to the GWT documentation it is possible to disable ofbuscation in general. From CssResource section "levers and knobs":

The configuration property CssResource.style may be set to pretty which will disable class-name obfuscation as well as pretty-print the CSS content. Combine this with a ClientBundle.enableInlining value of false to produce a CSS expression which is amenable to client-side editing.

In my work GWT project, I can see this property is actually set in Resources.gwt.xml (included in gwt-user.jar):

  <!-- This can be used to make CssResource produce human-readable CSS -->
  <define-configuration-property name="CssResource.style" is-multi-valued="false" />
  <set-configuration-property name="CssResource.style" value="obf" />

What is unclear to me is how to override this value, since it is already set. Did you manage to figure that out?

To disable obfuscation for all of you legacy classes at once, you can exploit what is said here

In short, in the legacy css file, which you are binding using CssResource bundle, put this declaration: @external .*;

All the classes in the file that has this declaration file will not be obfuscated.

You can use the @external directive to prevent a css classname from being obfuscated.

In your case, your css file might contain

@external top-table;
.top-table {
  some: rule;
}

To have not obfuscated class names you simply need to add following line to your gwt.xml file:

  <set-configuration-property name="CssResource.style" value="stable" />

When set to stable class names will consist of qualified class name followed by method name in your resource interfaces (of course with all . replaced by _)

All possible values for CssResource.style (for gwt 2.7) are:

  • pretty
  • debug
  • stable
  • stable-shorttype
  • stable-notype

To verify values available for your gwt version look at com.google.gwt.resources.rg.CssObfuscationStyle javadoc (or source code) for gwt version you're using.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!