GWT 的 CSS 冗余检查器
在我的项目中,我有很多 css 样式。其中一些从未使用过(不再使用)。我用 eclipse 手动检查:我选择文本,然后使用“搜索 -> 文本 -> 项目”我可以找到,如果这种样式仅出现在样式表中或也出现在 java 文件中。有没有更好的方法来检查我的 GWT 项目中当前使用了哪些样式?
编辑: @Igor,Keith:感谢您的提示,但我没有使用 CssResource
插入我的 css 文件。相反,我使用我的index.html。我想删除未使用的样式只是为了更好地概览。 CssResource
不完全是我正在寻找的。
In my project i have a lot of css styles. Some of them are never used (not anymore). I check this manually with eclipse: i select text and then with "Search -> Text -> Project" i can find, if this style occurs only in the stylesheet or also in java files. Is there better way to check, which styles are currently used in my GWT project?
edit:
@Igor,Keith: thanks for the hint, but i'm not using the CssResource
to insert my css file. Instead i use my index.html. And i want to remove the unused styles just for better overview. CssResource
is not exactly, what i'm looking for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用
CssResource
来注入您的 css 文件,GWT 将为您修剪未使用的样式(就像处理未使用的代码一样)。默认情况下它也会对其进行混淆,所以要小心。有关全面的说明,请参阅文档。CssResource
与 UiBinder 结合使用效果最佳。我推荐这两个 - 你甚至可以获得很酷的功能,比如当你的 UiBinder xml 文件中缺少 CSS 样式(或者你拼写错误)时出现编译时错误,以及其他很酷/很棒的东西 - 再次检查 文档查看完整列表。If you use
CssResource
to inject your css file, GWT will handle pruning unused styles for you (just like it does in the case of unused code). It will also by default obfuscate it, so watch out for that. For a comprehensive explanation see the docs.CssResource
works best in combination with UiBinder. I'd recommend both - you even get cool features like compilation-time errors when you are missing a CSS style in your UiBinder xml files (or you misspelled it), among other cool/awesome things - again, check the docs for the full list.GWT 2.0 添加了一个名为 ClientBundle 的功能,它是捆绑图像和 CSS 等资源文件的通用机制。如果将 CSS 文件与 ClientBundle 捆绑在一起(通过 CssResource 类),GWT 编译器实际上可能会在未使用的 CSS 选择器上生成错误。
该文档有点粗糙,但这里是 GWT 文档的相关部分:
http://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.html#Strict_scoping
除了检测缺失的选择器之外,
CssResource
还补充了 CSS 本身,让您可以使用CSS 中的常量和条件,甚至允许您根据所使用的浏览器指定不同的样式。它还提供混淆和缩小等功能。GWT 2.0 added a feature called ClientBundle, which is a generic mechanism for bundling resource files such as images and CSS. If you bundle CSS files with ClientBundle (via the
CssResource
class), the GWT compiler can actually generate errors on unused CSS selectors.The documentation is a bit rough, but here is the relevant part of the GWT docs:
http://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.html#Strict_scoping
In addition to detecting missing selectors,
CssResource
also supplements CSS itself, letting you use constants and conditionals within your CSS, even allowing you to specify different styles depending on which browser is being used. It also provides obfuscation and minification, among other things.我仍在寻找更好的解决方案。为了解决这个问题,我使用 linux 终端代替 eclipse 进行搜索,速度更快。
I'm still looking for a better solution. To solve the problem i've used the linux terminal instead eclipse for the search and that was faster.