Minifying JS/CSS

From UbikWiki

(Difference between revisions)
(Configuration)
(Set 1 environment variables:)

Line 11:

Line 11:

== Configuration using YUIAnt.jar ==
== Configuration using YUIAnt.jar ==
=== Download the ANT Jar [http://www.ubik-ingenierie.com/miscellanous/YUIAnt/YUIant.jar YUIAnt] ===
=== Download the ANT Jar [http://www.ubik-ingenierie.com/miscellanous/YUIAnt/YUIant.jar YUIAnt] ===
-
=== Set 1 environment variables: ===
+
=== Set 1 environment variable: ===
* YUI_COMPRESSOR_HOME (must point to [http://www.julienlecomte.net/yuicompressor/ YUICompressor] folder)
* YUI_COMPRESSOR_HOME (must point to [http://www.julienlecomte.net/yuicompressor/ YUICompressor] folder)
 +
=== Put your JS/CSS files to minify in js folder ===
=== Put your JS/CSS files to minify in js folder ===
=== Add this ANT target to your build file===
=== Add this ANT target to your build file===

Revision as of 20:59, 19 November 2007

Contents

Configuration from Project

Download this Eclipse project YUIAnt

Set 2 environment variables:

  • ANT_HOME
  • YUI_COMPRESSOR_HOME (must point to YUICompressor folder)

Run target jar to generate the YUIAnt.jar file in dist folder

Put your JS/CSS files to minify in js folder

Run target minify, minified files will be generated in jsmin

Configuration using YUIAnt.jar

Download the ANT Jar YUIAnt

Set 1 environment variable:

Put your JS/CSS files to minify in js folder

Add this ANT target to your build file

You will certainly have to modify the path to js and jsmin folders:

<target name="minify" depends="init" description="Minifiy a set of files">
		<available file="${dist.dir}/YUIAnt.jar" property="YUIANT_AVAILABLE" />
		<fail unless="YUIANT_AVAILABLE" message="Run jar target to generate the required task"/>
		<taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
			<classpath>
				<pathelement path="${env.YUI_COMPRESSOR_HOME}/build/yuicompressor-2.2.5.jar" />
				<pathelement path="${dist.dir}/YUIAnt.jar" />
			</classpath>
		</taskdef>
		<mkdir dir="${jsmin.dir}" />
		<yuicompress linebreak="300" warn="false" munge="yes" preserveallsemicolons="true" 
			outputfolder="${jsmin.dir}">
			<fileset dir="${js.dir}" >
				<include name="**/*.js" />
				<include name="**/*.css" />
			</fileset>
		</yuicompress>
	</target>

Run target minify, minified files will be generated in jsmin

Personal tools