Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grunt: uglify css files with uglifyjs

Tags:

gruntjs

I'm using grunt to uglify my static files (using grunt v0.4.0). I have configured it to uglify one file, but I can't figure out how to get it to do two files - despite reading this question and the usage examples.

Here's what I have currently:

uglify: {   options: {     banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',     mangle: true   },   build: {     src: 'dist/main.js',     dest: 'dist/main.min.js'   } } 

I'd like to uglify dist/main.css as well. How can I add it? I tried this, following the usage examples:

uglify: {   options: {     banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',     mangle: true   },   build: {     files: {       'dist/main.min.js': ['dist/main.js'],       'dist/main.min.css': ['dist/main.css']     }   } } 

But this gives me the following error:

WARN: ERROR: Unexpected token: punc ({) [dist/main.css:7,41] Warning: Uglification failed. Use --force to continue. Aborted due to warnings. 

Seems like it's choking on the first { - why would that happen? It is valid CSS.

like image 710
Richard Avatar asked Mar 20 '13 16:03

Richard


People also ask

Can we Uglify CSS?

Uglify is for Javascript not CSS. Try using http://github.com/gruntjs/grunt-contrib-cssmin to minify CSS using Grunt.

What is Uglify CSS?

UglifyJS is a JavaScript parser/compressor/beautifier toolkit. It can be used to combine and minify JavaScript assets so that they require less HTTP requests and make your site load faster. UglifyCSS is a CSS compressor/beautifier that is very similar to UglifyJS.

What is grunt Uglify?

loadNpmTasks('grunt-contrib-uglify'); } Minification of JS files can now be achieved by running the command. grunt uglify. But a task, or a set of tasks, can be run together under an "alias task". The grunt.registerTask function serves this purpose.


2 Answers

Uglify is for Javascript not CSS. Try using http://github.com/gruntjs/grunt-contrib-cssmin to minify CSS using Grunt.

like image 110
drzax Avatar answered Sep 18 '22 18:09

drzax


Uglify is for Javascript only, but YUI Compressor can do both Javascript and CSS: YUI Compressor

like image 21
jchadhowell Avatar answered Sep 19 '22 18:09

jchadhowell