Frage

I'm trying to use a gruntfile to uglify my JS and CSS. The one problem is that uglify doesn't work, the terminal gives a very vague error...

Gruntfile.js

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify:
    {
      js:
      {
        files: { 'compressed/javascript.min.js': ['js/*.js'] }
      },
      css:
      {
        files: { 'compressed/css.min.css': ['css/*.css'] }
      }
    }
  });

  // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-contrib-uglify');

  // Default task(s).
  grunt.registerTask('default', ['uglify']);

};

package.json

{
  "name": "my-project-name",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-jshint": "~0.6.3",
    "grunt-contrib-nodeunit": "~0.2.0",
    "grunt-contrib-uglify": "~0.2.2",
    "grunt-contrib-imagemin": "~0.3.0"
  }
}

Terminal output:

MacBook-Pro-van-Valerie:grunt valerieeskens$ grunt
Running "uglify:js" (uglify) task
>> Uglifying source "js/javascript1.js,js/javascript2.js" failed.
Warning: Uglification failed. Use --force to continue.

Aborted due to warnings.
MacBook-Pro-van-Valerie:grunt valerieeskens$ 

Map structure: http://d.pr/i/CxVJ

War es hilfreich?

Lösung

Uglify is for JavaScript, not CSS. Use grunt-contrib-cssmin if you want to compress your CSS files. The problem here seems to be the JS itself though, and I've tried that pattern in my Uglify config and it works OK. Have you run JSHint on your JavaScript source files? It may be a problem with the input itself.

Andere Tipps

Uglify is only for JavaScript, so you should use another Grunt plugin to minify your CSS. However, even then your javascript needs to be valid. Otherwise the minification will fail. For example the following will not pass:

var name = "Steve;

or

if(condition1 &&) {
   // ...
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top