2013-09-30 78 views
0

我正在嘗試使用gruntfileuglify我的JS和CSS。有一個問題是,uglify不起作用,終端提供了一個非常模糊的錯誤...Grunt:「Uglification failed」

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" 
    } 
} 

端子輸出:

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$ 

地圖結構:http://d.pr/i/CxVJ

回答

0

uglify用於JavaScript,而不是CSS。如果要壓縮CSS文件,請使用grunt-contrib-cssmin。這裏的問題似乎是JS本身,而我已經在我的Uglify配置中嘗試過這種模式,並且它工作正常。你在JavaScript源文件上運行JSHint嗎?這可能是輸入本身的問題。

0

Uglify僅適用於JavaScript,因此您應該使用另一個Grunt插件來縮小您的CSS。但是,即使那樣你的JavaScript需要是有效的。否則縮小將失敗。例如,下面將不會通過:

var name = "Steve; 

if(condition1 &&) { 
    // ... 
}