EmptyM / usemin-maven-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Usemin Maven Plugin

Build Status

The Usemin Maven plugin is a tool inspired by grunt-usemin, which replaces references from non-optimized scripts and stylesheets to their optimized version within a set of HTML and JSP files using :

CSS compression (with LESS support)

<!-- build:css styles/app.css -->
<link rel="stylesheet" href="styles/main.css">
<link rel="stylesheet" href="styles/custom.css">
<link rel="stylesheet" type="text/x-less" href="styles/bootstrap.less"/>
<script src="libs/less-1.7.0.js"></script>
<!-- endbuild -->

JS compilation

<!-- build:js scripts/podbox.js -->
<script>
    var toto = "podbox rocks !";
    console.log(toto);
</script>
<script src="scripts/app.js"></script>

<script src="scripts/controllers/mapping.js"></script>

<script src="scripts/directives/dragndrop.js"></script>

<script src="scripts/services/model.js"></script>
<script src="scripts/services/services.js"></script>
<!-- endbuild -->

JSP context path support

<!-- build:css ${pageContext.request.contextPath}/styles/app.css -->
<link rel="stylesheet" href="${pageContext.request.contextPath}/styles/main.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/styles/custom.css">
<!-- endbuild -->

<!-- build:js ${pageContext.request.contextPath}/scripts/podbox.js -->
<script src="${pageContext.request.contextPath}/scripts/app.js"></script>
<!-- endbuild -->

CDN replace (html files only)

<link rel="stylesheet" href="libs/jquery-ui-1.11.2.css"
      data-cdn="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.css">

<script src="libs/jquery-ui-1.11.2.js"
        data-cdn="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>

Maven Config

<build>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <executions>
                <execution>
                    <id>default-war</id>
                    <phase>package</phase>
                    <goals>
                        <goal>war</goal>
                    </goals>
                    <configuration>
                        <warSourceExcludes>
                            index.html,
                            mapping.html
                        </warSourceExcludes>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.podbox</groupId>
            <artifactId>usemin-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>usemin</goal>
                    </goals>
                    <configuration>
                        <!-- http://javadoc.closure-compiler.googlecode.com/git/com/google/javascript/jscomp/CompilerOptions.LanguageMode.html -->
                        <!-- default: ECMASCRIPT5_STRICT -->
                        <languageMode>ECMASCRIPT5_STRICT</languageMode>
                        
                        <!-- http://javadoc.closure-compiler.googlecode.com/git/com/google/javascript/jscomp/CompilationLevel.html -->
                        <!-- default: SIMPLE_OPTIMIZATIONS -->
                        <compilationLevel>ADVANCED_OPTIMIZATIONS</compilationLevel>
                        
                        <!-- https://github.com/marceloverdijk/lesscss-java -->
                        <!-- default: no options -->
                        <lessOptions>
                            <lessOption>--relative-urls</lessOption>
                        </lessOptions>
                        
                        <sources>
                            <source>index.html</source>
                            <source>mapping.html</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Gradle Task

buildscript {
    dependencies {
        classpath "com.podbox:usemin-maven-plugin:$useminPluginVersion"
    }
}

sourceSets { main { resources { exclude 'static/index.html' } } }

task usemin(dependsOn: processResources, type: com.podbox.UseMinTask) {
    sourceEncoding = 'UTF-8'
    sourceDirectory = file('src/main/resources/static')
    targetDirectory = file('build/resources/main/static')
    languageMode = 'ECMASCRIPT5_STRICT'
    compilationLevel = 'SIMPLE_OPTIMIZATIONS'
    sources = [ 'index.html' ]
}
task jar.dependsOn(usemin)

About


Languages

Language:JavaScript 66.5%Language:Java 33.5%