This project aims to be a simple asset pipeline for JSP applications. It was inspired by the likes of BakeHouse. Check out the demo project or see the quickstart.
- Add my GitHub Maven Repository & the asset-pipeline dependency to your pom.xml. This example uses the Google Closure adapter (which is the only implementation available now)
<repositories>
<repository>
<id>ntier-repo</id>
<url>https://github.com/dwelch2344/maven-repo/raw/master/releases</url>
</repository>
<repository>
<id>ntier-snapshot-repo</id>
<url>https://github.com/dwelch2344/maven-repo/raw/master/snapshots</url>
<snapshots>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>co.ntier.web</groupId>
<artifactId>asset-pipeline-closure</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- Your dependencies HERE! -->
</dependencies>
- Configure your ServletContext as appropriate. The following example uses Spring's JavaConfig to hook things up correctly
@Configuration
@EnableWebMvc
@EnableAspectJAutoProxy(proxyTargetClass=true)
public class WebConfig extends WebMvcConfigurerAdapter {
@Inject ServletContext ctx;
@PostConstruct
public void onSetup(){
// comment the next line out to prevent minification
ctx.setAttribute(PipelineConstants.IS_PRODUCTION_KEY, true);
ctx.setAttribute(PipelineConstants.RESOURCE_COMPILER_KEY, new ClosureResourceCompiler());
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// add the generated sources folder for serving static content
registry.addResourceHandler("/gen/**").addResourceLocations("/gen/");
}
}
NOTE: The /gen/
mapping should correspond to the prefix used in the next step...
- Declare your resources in your JSP
<%@ taglib prefix="pipeline" uri="http://ntier.co/pipeline" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Generated code will be here -->
<%-- Note that the "/gen" prefix corresponds to the ResourceHandler mapping in step 2 --%>
<pipeline:scripts ref="/gen/app.js">
<pipeline:script src="/resources/app1.js"/>
<pipeline:script src="/resources/app2.js"/>
<%-- <pipeline:script src="/resources/app3.js"/> --%>
</pipeline:scripts>
</head>
- Enjoy!
When developing, just comment out the IS_PRODUCTION_KEY
line from the configuration file and you'll get the raw resources.