Minifying JS/CSS

From UbikWiki

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

Line 1:

Line 1:

-
== Configuration ==
+
== Configuration from Project ==
-
=== Download this Eclipse project [http://www.ubik-ingenierie.com/miscellanous/YUIAnt/Yuiant.zip YUIAnt] ===
+
=== Download this Eclipse project [http://www.ubik-ingenierie.com/miscellanous/YUIAnt/YUIant.zip YUIAnt] ===
=== Set 2 environment variables: ===
=== Set 2 environment variables: ===
* ANT_HOME
* ANT_HOME

Line 7:

Line 7:

=== Run target jar to generate the YUIAnt.jar file in dist folder ===
=== Run target jar to generate the YUIAnt.jar file in dist folder ===
=== Put your JS/CSS files to minify in js 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 [http://www.ubik-ingenierie.com/miscellanous/YUIAnt/YUIant.jar YUIAnt] ===
 +
=== Set 1 environment variables: ===
 +
* YUI_COMPRESSOR_HOME (must point to [http://www.julienlecomte.net/yuicompressor/ YUICompressor] folder)
 +
=== 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:
 +
<source lang="xml">
 +
<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></source>
=== Run target minify, minified files will be generated in jsmin ===
=== Run target minify, minified files will be generated in jsmin ===

Revision as of 20:58, 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 variables:

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