3

我是 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']);
};

但我有这个消息:

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.

我的配置有什么问题吗?

谢谢

4

2 回答 2

0

The problem here is that grunt-contrib-uglify returns this error when compressing "semi-colon-less" or "compact" javascript.

This is legal javascript, but it doesn't even look (to me) like the same language! See the short example at the top of this bug report 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

It would seem grunt-contrib-uglify should be able to handle any valid javascript - but it does not.

于 2014-10-30T01:58:58.133 回答
0

我假设您现在可能已经继续前进了,但是如果 JavaScript 中出现问题,uglify 可能会失败。它不像 JSHint 说的那么严格,但是如果你只是有糟糕的 JS,那么 uglify 就会出现 uglify-ing 的问题。

这也可能是由于脚本的错误顺序而发生的(即尝试在 jQuery 之前加载 jQuery 插件,也许?)。

于 2013-10-21T02:42:41.520 回答