maven – ECMASCRIPT 5与wro4j和谷歌闭包编译器

我们正在使用wro4j和Google Closure以及Maven来缩小我们的JS.默认情况下,它不支持JS中的严格模式(“use strict”;)..它只是删除它.我可以在pom.xml或其他地方做任何配置,让它在那里使用strict吗?

这是谷歌关闭编译器的配置:

--language_in=ECMASCRIPT5_STRICT

不知道如何将其插入Wro4j.有任何想法吗?

最佳答案 创建经理工厂的自定义实现,添加
ECMAScript5

public class MyCustomWroManagerFactory
extends DefaultStandaloneContextAwareManagerFactory
  {
  @Override 
    protected ProcessorsFactory newProcessorsFactory() 
      {
      final SimpleProcessorsFactory factory = new SimpleProcessorsFactory(); 

      factory.addPreProcessor(
           new GoogleClosureCompressorProcessor(
             CompilerOptions.LanguageMode.ECMASCRIPT5_STRICT
                                               )
                        ); 

      return factory;
      }
  }

在pom.xml中引用它作为wroManagerFactory节点的值:

<configuration>
  <wroManagerFactory>com.mycompany.MyCustomWroManagerFactory</wroManagerFactory>
</configuration>

According to John Lenz from the Closure Compiler project, if you are using the Compiler API directly, you should specify a CodingConvention.

参考

> GoogleClosureCompressorProcessor.java – method setCompilerOptions
> GoogleClosureCompressorProcessor.java – optionsPool method
> Closure Compiler Service API Reference – language |  Closure Compiler  |  Google Developers

点赞