简体   繁体   English

Grunt丑化步骤失败

[英]Grunt uglifying step failing

I am new to Grunt and I am trying to use it with this config 我是Grunt的新手,我正在尝试使用此配置

module.exports = function(grunt) {

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    // Define our source and build folders
    js_src_path: 'javascripts',
    js_build_path: "build/js",

// Grunt Tasks
    concat: {
      options:{
        separator: ';'
      },
      js: {
        src: ['<%= js_src_path %>/*.js'],
        dest: '<%= js_build_path %>/app.js'
      }    },
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
      },
      js: {
        src: '<%= concat.js.dest %>',
        dest:'<%= js_build_path %>/app.min.js'
      }
    }
    }
  );

  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');

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

But I have this message : 但我有这样的信息:

Running "concat:js" (concat) task
File "build/js/app.js" created.

Running "uglify:build" (uglify) task
>> Uglifying source "build/js/app.js" failed.
Warning: Uglification failed. Use --force to continue.

Aborted due to warnings.

Is there anything wrong with my config ? 我的配置有什么问题吗?

Thanks 谢谢

I assume you've probably moved on by now, but the uglify can fail if there was something wrong in the JavaScript. 我猜你现在可能已经开始了,但是如果JavaScript出现问题,uglify可能会失败。 It's not as strict as say, JSHint, but if you simply have bad JS, uglify will have problems uglify-ing. 它不像JSHint那么严格,但如果你只是有不好的JS,那么uglify将会出现问题。

This can also happen because of a bad order of scripts (ie trying to load a jQuery plugin before jQuery, perhaps?). 这也可能是因为脚本顺序不好(即尝试在jQuery之前加载jQuery插件,也许?)。

The problem here is that grunt-contrib-uglify returns this error when compressing "semi-colon-less" or "compact" javascript. 这里的问题是grunt-contrib-uglify在压缩“无结肠”或“紧凑”javascript时会返回此错误。

This is legal javascript, but it doesn't even look (to me) like the same language! 这是合法的javascript,但它甚至看起来(对我来说)都是同一种语言! See the short example at the top of this bug report https://github.com/gruntjs/grunt-contrib-uglify/issues/29 . 请参阅此错误报告顶部的简短示例https://github.com/gruntjs/grunt-contrib-uglify/issues/29

For more information regarding this "compact style" see: http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding 有关此“紧凑风格”的更多信息,请参阅: http//blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding

It would seem grunt-contrib-uglify should be able to handle any valid javascript - but it does not. 它似乎是grunt-contrib-uglify应该能够处理任何有效的JavaScript - 但事实并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM