I'm doing a Spring MVC 4.2 project.
In this project I have more than one CSS file and more than one JS .
What I want is to make all CSSs files into a single ALL.css and that this file is minify
.
What I have been working on is a setting that places resources in a pre-defined directory. The configuration is this:
VersionResourceResolver versionResolver = new VersionResourceResolver()
.addFixedVersionStrategy(version, "/**/*.js", "/**/*.css")
.addContentVersionStrategy("/**");
registry.addResourceHandler("/public-resources/**")
.addResourceLocations("/resources/")
.setCachePeriod(1)
.resourceChain(true)
.addResolver(versionResolver)
.addTransformer(appCacheTransformer);
With this I can access the files in view like this:
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<link rel="stylesheet" type="text/css" href="<spring:url value="/resources/css/magnific-popup.css"/>">
The result in HTML is this:
<link rel="stylesheet" type="text/css" href="/MeuProjeto/public-resources/css/magnific-popup.css">
Everything works.
Is there any way to unify CSSs in a single all.css file and call it that? Is Spring able to do this?
<link rel="stylesheet" type="text/css" href="<spring:url value="/resources/css/all.css"/>">
I found some plugins that were supposed to work for this, I found wro4j that you can not even begin to use, by adding the dependency in pom.xml
it can not read the repository.
UPDATE
I'm updating to include attempts and doubts in the question, I think it will help future readers.
The first attempt with the minify-maven-plugin.
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.4</version>
<executions>
<execution>
<id>default-minify</id>
<configuration>
<charset>UTF-8</charset>
<cssSourceDir>resources/css</cssSourceDir>
<cssSourceFiles>
<cssSourceFile>Site.css</cssSourceFile>
<cssSourceFile>style.css</cssSourceFile>
</cssSourceFiles>
<cssFinalFile>all.css</cssFinalFile>
<jsSourceDir>resources/js</jsSourceDir>
<jsSourceFiles>
<jsSourceFile>index.js</jsSourceFile>
<jsSourceFile>sendmail.js</jsSourceFile>
</jsSourceFiles>
<jsFinalFile>all.js</jsFinalFile>
<jsEngine>CLOSURE</jsEngine>
</configuration>
<goals>
<goal>minify</goal>
</goals>
</execution>
</executions>
</plugin>
I used the view like this:
<link rel="stylesheet" type="text/css" href="<spring:url value="/resources/css/all.css"/>">
Generated the following output:
<link rel="stylesheet" type="text/css" href="/Isabele/resources/css/all.css">
But the all.css file is not there, giving 404. At the test level I have not changed the other css files in the view, so the two files used in the Site.css and style.css plugin configuration are being used just like the all.css and both are in place and responding.