Last active
December 28, 2015 05:19
-
-
Save HerbertV/7448628 to your computer and use it in GitHub Desktop.
ANT snippets for concat, minfiy css and js and link replacing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
=========================================================================== | |
Some ANT Snippets combine, minify and JS and CSS files. | |
=========================================================================== | |
For deploying homepages with ANT. | |
Properties: | |
dir.src=your source folder | |
dir.deploy=your deploy folder | |
--> | |
<!-- | |
=========================================================================== | |
TASK DEFINITIONS | |
=========================================================================== | |
--> | |
<!-- http://ant-contrib.sourceforge.net/ --> | |
<taskdef resource="net/sf/antcontrib/antlib.xml"> | |
<classpath> | |
<pathelement location="ant-contrib/ant-contrib-1.0b3.jar"/> | |
</classpath> | |
</taskdef> | |
<!-- | |
YUI Ant: | |
http://www.ubik-ingenierie.com/ubikwiki/index.php?title=Minifying_JS/CSS | |
YUI Compressor: | |
https://github.com/yui/yuicompressor/releases | |
--> | |
<taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask"> | |
<classpath> | |
<pathelement path="antlib/YUIAnt.jar" /> | |
<pathelement path="antlib/yuicompressor-2.4.8.jar" /> | |
</classpath> | |
</taskdef> | |
<!-- | |
=========================================================================== | |
Target collect_and_concat | |
=========================================================================== | |
--> | |
<target name="collect_and_concat" | |
description="combines css and js files."> | |
<concat destfile="min.js" fixlastline="yes"> | |
<filelist refid="list_of_js_files_to_combine"/> | |
</concat> | |
<concat destfile="min.css" fixlastline="yes"> | |
<filelist refid="list_of_css_files_to_combine"/> | |
</concat> | |
</target> | |
<!-- | |
=========================================================================== | |
Target minify | |
=========================================================================== | |
--> | |
<target name="minify" | |
description="Minifiy all CSS and JS"> | |
<yuicompress linebreak="300" | |
warn="false" | |
munge="yes" | |
preserveallsemicolons="true" | |
outputfolder="${dir.deploy}" | |
> | |
<fileset file="${dir.src}min.js"/> | |
</yuicompress> | |
<yuicompress linebreak="300" | |
warn="false" | |
munge="yes" | |
preserveallsemicolons="true" | |
outputfolder="${dir.deploy}" | |
> | |
<fileset file="${dir.src}min.css"/> | |
</yuicompress> | |
<delete file="${dir.src}min.css" /> | |
<delete file="${dir.src}min.js" /> | |
</target> | |
<!-- | |
=========================================================================== | |
Target replace_references | |
=========================================================================== | |
mark in your css and js references with: | |
<!--sourcejs-->... your js links... <!--sourcejsend--> | |
<!--sourcecss-->... your js links... <!--sourcecssend--> | |
--> | |
<target name="replace_references"> | |
<replaceregexp match="\<!--sourcejs--\>(.*?)\<!--endsourcejs--\>" | |
replace="\<script src='min.js'\>\</script\>" | |
flags="gs"> | |
<fileset name="${dir.deploy}*.html"/> | |
</replaceregexp> | |
<replaceregexp match="\<!--sourcecss--\>(.*?)\<!--endsourcecss--\>" | |
replace="\<link href='min.css' rel='stylesheet'/\>" | |
flags="gs"> | |
<fileset file="${dir.deploy}*.html"/> | |
</replaceregexp> | |
</target> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment