This page is about how to apply a processor only on resources with a specific extension. The ExtensionsAwareProcessorDecorator is another default implementation of ProcessorsDecorator which enforce decorated processors to be applied only on predefined extension or a list of extensions.

By default wro4j deals with two types of resources: CSS & JS. Therefore, if a processor is annotated with @SupportedResourceType(ResourceType.JS), then it will be applied on all js resources. Similarly, when a processor is annotated with @SupportedResourceType(ResourceType.CSS) - then it will be applied for all css resources. There is a third type of processors, which have no @SupportedResourceType annotation - meaning that it will be applied to both type of processors.

This default behavior can be unacceptable in some situations. For example, it doesn't make sense to apply !CoffeeScriptProcessor on other resources than those with *.coffee extension. The same applies for less css resources.

One limitation of ExtensionsAwareProcessorDecorator is that it requires to know about resource extension, therefore it can decorate only preprocessors. This is because postprocessors do not have such information, since they are applied only after all resources from a certain group are merged.

Usage Example

In this example the JsMinProcessor is decorated and applied only on resources having *.js extension. Notice that addExtension method is used to specify the extension on which the processor should be applied.

ExtensionsAwareProcessorDecorator.decorate(new JsMinProcessor()).addExtension("js");

The next example decorates !CoffeeScriptProcessor. The decorated processor is applied only on resources with *.coffee extension.

ExtensionsAwareProcessorDecorator.decorate(new CoffeeScriptProcessor()).addExtension("coffee");

When you need to apply a processor on a list of extensions, you can invoke the addExtension method multiple times. Example:

ExtensionsAwareProcessorDecorator.decorate(new LessCssProcessor()).addExtension("less").addExtension("lessCss").addExtension("css");

The newly created processor will be applied only on resources having one of the following extensions: less, lessCss, css.

Using ExtensionsAwareProcessorDecorator in configuration options

An alternative way of using !ExtensionsAwareProcessorDecorator is by configuring preProcessors configuration option. Example

Whenever a preprocessor alias contains a dot (.) character followed by an extension, the preprocessor is decorated with ExtensionsAwareProcessorDecorator with found extension added.

Another example:


The above configuration will decorate lessCss processor and will be applied only on resources having less extension.