4

我正在尝试使用带有 grunt 的 uglify 来连接和缩小一些文件。我已经使用 npm 来install grunt-contrib-uglify.

我的grunt.js文件中有以下内容:(我已经删除了一些其他匿名任务)

module.exports = function(grunt) {

  'use strict';      

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

    uglify: {
        options: {
            sourceMap: 'app/map/source-map.js'
        },
        files: {
            'app/dist/sourcefiles.min.js': [
                'app/test_js/test.js'
              ]
        }
    }

};

然后我运行:

grunt uglify

但我不断收到以下错误:

Warning: Maximum call stack size exceeded Use --force to continue.

如果我使用武力,咕噜任务永远不会停止运行。

有人可以告诉我哪里出错了吗?我正在把头发扯下来。

4

2 回答 2

11

我遇到了同样的问题,使用了另一个 Grunt 插件,称为凹槽。错误消息不明确。

Warning: Cannot read property 'message' of undefined Use --force to continue.

但是详细模式显示我的任务被调用了数百次。问题是我在注册任务时创建了“循环依赖”(导致无限循环)。

grunt.registerTask('recess', ['recess']); //does not work => cyclic dependency! 

registerTask 方法的第一个参数是“别名任务”,必须与第二个参数中定义的任务名称不同。我这样纠正:

grunt.registerTask('my-recess-task', ['recess']);

我运行了调用它的任务(在命令提示符窗口中)

grunt my-recess-task

然后就OK了!

有关 registerTask() 方法的更多信息,来自 grunt API: http: //gruntjs.com/api/grunt.task#grunt.task.registertask

于 2013-08-15T22:31:01.483 回答
3

我也遇到了这个问题,我通过删除解决了这个问题 grunt.registerTask('uglify', ['uglify']);

在我解决这个问题之前,我跑去grunt uglify -v检查发生了什么。

我发现它是因为你在哪里使用它grunt.loadNpmTasks('grunt-contrib-uglify');,它隐式执行grunt.registerTask('uglify', ['uglify']);^_^

于 2014-03-04T05:05:24.267 回答