Grunt:“丑化失败”

时间:2013-09-30 20:29:04

标签: node.js gruntjs uglifyjs

我正在尝试使用gruntfile uglify我的JS和CSS。一个问题是uglify不起作用,终端给出了一个非常模糊的错误......

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

2 个答案:

答案 0 :(得分:0)

Uglify适用于 JavaScript ,而非CSS。如果要压缩CSS文件,请使用grunt-contrib-cssmin。这里的问题似乎是JS本身,我在我的Uglify配置中尝试了这种模式,它运行正常。您是否在JavaScript源文件上运行JSHint?这可能是输入本身的问题。

答案 1 :(得分:0)

Uglify仅适用于JavaScript,因此您应该使用另一个Grunt插件来缩小CSS。但是,即使这样你的javascript也需要有效。否则缩小将失败。例如,以下内容不会通过:

var name = "Steve;

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