Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenating CSS files in a specific order

I have a series of CSS files that I am concatenating and minfying (using the YUI Compressor) with an Ant build script. The CSS files are:

  • Reset.css
  • Formalize.css
  • Typography.css
  • Site.css

There are other CSS files like ie.css and editor.css that I don't want to include in the minification. I have my build script working with the following code, but the problem now is that the files need to be concatenated in the order posted above.

<target name="minifycss">
    <!-- Combine all CSS files except for ones specified for IE or the content editor -->
    <concat destfile="css/e123-1.css">
        <fileset dir="css" includes="*.css" excludes="ie.css editor.css print.css" />
    </concat>

    <!-- Minify the css -->
    <java fork="true" jar="${yuicompressor.lib}" dir="css" output="css/e123-1.min.css">
        <arg value="e123-1.css" />
    </java>
</target>

I assume that the files are added alphabetically, but I was wondering if there was a way to tell Ant what order to concatenate the files without renaming them to 1reset.css, 2formalize.css, etc.

like image 849
Dave Long Avatar asked Jul 09 '11 16:07

Dave Long


2 Answers

Use a filelist, as shown in the ant concat documentation.

like image 111
JB Nizet Avatar answered Sep 20 '22 22:09

JB Nizet


If using wro4j, you can control the order of the resources to concatenate like this:

      <groups>
         <group name="all">
           <css>/static/reset.css</css>
           <css>/static/fonts.css</css>
           <css>/wildcard/*.css</css>
           <js>/static/js/lib/core.js</js>
         </group>
      </groups>

It allows you to use wildcards and also can be used for javascript resources (not only css)

This is a biased answer, because i'm working on wro4j project.

like image 28
Alex Objelean Avatar answered Sep 20 '22 22:09

Alex Objelean