|
MavenPluginWithYuiOrGoogleClosure
Describes how wro4j maven plugin can be used to use google closure compiler or YUI compressor
IntroductionSince 1.3.x branch release, wro4j provides some fixes which allows easily customize the way your resources are compressed. Wro4j Maven Plugin with Google ClosureGoogle closure compiler is one of the best compressors out there. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls. Note: the wro4j factory invokes Google Closure Compiler with SIMPLE_OPTIMIZATIONS. In order to make it work with wro4j maven plugin you have to do the following:
<dependency>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-extensions</artifactId>
<version>${wro4j.version}</version>
</dependency>
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>${wro4j.version}</version>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<wroManagerFactory>ro.isdc.wro.extensions.manager.standalone.GoogleStandaloneManagerFactory</wroManagerFactory>
</configuration>
</plugin>Alternatively you can configure the managerFactory from the command line when invoking manually the plugin: mvn wro4j:run -DwroManagerFactory=ro.isdc.wro.extensions.manager.standalone.GoogleStandaloneManagerFactory Wro4j Maven Plugin with YUICompressorYUICompressor is also very popular tool. Tests on the YUI Library have shown savings of over 20% compared to JSMin (becoming 10% after HTTP compression). It does also compress CSS files, not only javascripts. In order to make it work with wro4j maven plugin, you have to follow similar steps as with google closure compiler:
<dependency>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-extensions</artifactId>
<version>${wro4j.version}</version>
</dependency> <plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>${wro4j.version}</version>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<wroManagerFactory>ro.isdc.wro.extensions.manager.standalone.YUIStandaloneManagerFactory</wroManagerFactory>
</configuration>
</plugin>Alternatively you can configure the managerFactory from the command line when invoking manually the plugin: mvn wro4j:run -DwroManagerFactory=ro.isdc.wro.extensions.manager.standalone.YUIStandaloneManagerFactory | |
Can you provide a more extensive explanation of what this configuration does? Perhaps you could additionally provide an example that does the following:
Input files: src/main/javascript/com/example/js/foo.js src/main/javascript/com/example/js/bar.js
Output files: target/classes/com/example/js/foo-min.js target/classes/com/example/js/bar-min.js
Thanks.
When using wro4j, you don't have to manually add files to compress and the output file location. All you have to do, is to define wro.xml file which describes how resources are grouped. This is described here: http://code.google.com/p/wro4j/wiki/GettingStarted and http://code.google.com/p/wro4j/wiki/MavenPlugin
Is it possible to set the Closure Compiler optimization level to ADVANCED_OPTIMIZATIONS?
Thanks
Yes, it is. Create a custom implementation of manager factory, similar to GoogleStandaloneManagerFactory?
Example:
public class GoogleStandaloneManagerFactory? extends DefaultStandaloneContextAwareManagerFactory? {
}
and use this class when setting the wroManagerFactory property value
Hi, is it possible to configure closure compiler to strip out a specified regex pattern from your javascript files?
thanks Jon
That is actually a question for google closure compiler developers. If it is possible, than you can create a custom implementation of GoogleClosureCompressorProcessor? which does exactly what you need and add that custom processor to the processorsFactory.
Alex, could you add ADVANCED_OPTIMIZATIONS version of a Factory to your standard distribution?
I will add a new factory which will use ADVANCED_OPTIMIZATION.
Alex, thanks a lot! Waiting for new release!
ADVANCED_OPTIMIZATION is available:
<plugin> <groupId>ro.isdc.wro4j</groupId> <artifactId>wro4j-maven-plugin</artifactId> <version>1.4.1</version> <executions> <execution> <phase>compile</phase> <goals> <goal>run</goal> </goals> </execution> </executions> <configuration> <targetGroups>all</targetGroups> <destinationFolder>${basedir}/src/main/webapp/dst/</destinationFolder> <contextFolder>${basedir}/src/main/webapp/</contextFolder> <wroManagerFactory>ro.isdc.wro.extensions.manager.standalone.GoogleAdvancedStandaloneManagerFactory</wroManagerFactory> </configuration>` </plugin>Do you mean disable minimization? If yes, use the minimize flag and set it to false. We can continue this subject on the mailing list (which is more appropriate for this kind of discussion).