avasin
avasin

Reputation: 9726

Minify and join CSS & JS files on linux, server side

In my project, for example, I have this structure:

/public/js/src/ /* many jquery plugins there */
/public/css/src/ /* many css files there, that describe different things */

After changes have been made, I would like to type in command line something like:

root@hostname:/var/www/test/public# ./build

which would generate two files:

/public/css/build.css - all files from /public/css/src/ folder with minified source
/public/js/build.js - all files from /public/js/src folder with minified source

For the moment I am using less css, which is working on node. I would like to have one script that will do everything, for css as for javascript. Could you please advise the best way to "build" dev-source javascript & css files?

Upvotes: 2

Views: 11407

Answers (5)

George Katsanos
George Katsanos

Reputation: 14175

You can use YUI Compressor. I'm sure it's also available for Linux. It works from the command line. Read here how it works.

Example:

java -jar yuicompressor-x.y.z.jar myfile.js -o myfile-min.js --charset utf-8

I'm sure you can setup a simple Bash script that executes two commands, one for CSS and one for JS by using parameters as input.

Upvotes: 6

Yuri Okada
Yuri Okada

Reputation: 21

Use ACCSS for css compression, its compression rate is better than YUI-Compressors and its written in c with automake installation, so it is portable to almost every system.

Like above, you can use a shell script to combine less and accss. accss support reading from stdin, so you can combine them with

lessc styles.less | accss > out.css

It also has severeal compatibility options, especially for Internet Explorer.

https://github.com/acwtools/accss

Upvotes: 1

Pawel
Pawel

Reputation: 393

YUI-Compressor is available as a package in any Ubuntu version.

apt-get install yui-compressor

Hope it helps

Upvotes: 4

Barry Kooij
Barry Kooij

Reputation: 410

I know this is an old question, but for those getting here through Google. You can easily use Compass for this.

compass compile --output-style compressed --force

More info: http://compass-style.org/help/tutorials/production-css/

Upvotes: 2

Rayraegah
Rayraegah

Reputation: 204

You can use Apache ANT and YUI Compressor to set up your own build process. You can minify all your JS and CSS files with a single command.

EDIT: if you want a sample project try H5bp's ant build scripts http://html5boilerplate.com/

Upvotes: 2

Related Questions