grunt-contrib-requirejs任务会在没有错误的情况下停止Grunt

时间:2013-08-23 12:05:29

标签: node.js requirejs gruntjs r.js grunt-contrib-requirejs

我遇到问题,我的grunt-contrib-requirejs任务停止了我的咕噜声进程。这样做没有任何错误。我需要帮助来确定问题。

我的总体任务

grunt.registerTask('build', [
    'clean:dist',
    'jshint',
    'handlebars',
    'requirejs',
    'concat:dist',
    'uglify',
    'compass',
    'imagemin',
    'cssmin',
    'copy'
]);

这是我的任务配置

requirejs: {
    dist: {
        options: {
            baseUrl: 'app',
            optimize: 'none',
            optimizeCss: 'none', // We use cssmin for this
            preserveLicenseComments: true,
            dir: 'dist/',

            useStrict: true,
            wrap: false,
            findNestedDependencies: true,

            //If set to true, any files that were combined into a build bundle will be
            //removed from the output folder.
            removeCombined: true,

            paths: {
                aura: '<%= settings.bower %>/aura/lib/aura',
                underscore: '<%= settings.bower %>/underscore/underscore',
                eventemitter: '<%= settings.bower %>/eventemitter2/lib/eventemitter2',
                backbone: '<%= settings.bower %>/backbone/backbone',
                handlebars: '<%= settings.bower %>/handlebars/handlebars',
                text: '<%= settings.bower %>/requirejs-text/text',
                jquery: '<%= settings.bower %>/jquery/jquery'
            },

            shim: {
                backbone: {
                    exports: 'Backbone',
                    deps: ['underscore', 'jquery']
                },
                underscore: {
                    exports: '_'
                },
                handlebars: {
                    exports: 'Handlebars'
                }
            },

            modules: [{
                name: "app",
                include: ["aura","jquery"]
            }],

            onBuildWrite: function( name, path, contents ) {
                grunt.log.writeln( 'Writing: ' + name );
                return contents
            },

            done: function(done, output) {
                var duplicates = require('rjs-build-analysis').duplicates(output);

                if (duplicates.length > 0) {
                    grunt.log.subhead('Duplicates found in requirejs build:');
                    grunt.log.warn(duplicates);
                    done(new Error('r.js built duplicate modules, please check the excludes option.'));
                }

                grunt.log.writeln('All done');

                done();
            }

        }
    }
}

我尝试使用-v标志运行它,但我没有收到任何错误或警告。它然后停止,并且不运行我定义的其他任务,我没有得到我定义的自定义日志。我得到了这个输出:

Running "requirejs" task

Running "requirejs:dist" (requirejs) task
Verifying property requirejs.dist exists in config...OK
File: [no files]
Options: logLevel=0, done=undefined, baseUrl="app", optimize="none", optimizeCss="none", preserveLicenseComments, dir="dist/", useStrict, wrap=false, findNestedDependencies, removeCombined, paths={"aura":"bower_components/aura/lib/aura","underscore":
"bower_components/underscore/underscore","eventemitter":"bower_components/eventemitter2/lib/eventemitter2","backbone":"bower_components/backbone/backbone","handlebars":"bower_components/handlebars/handlebars","text":"bower_components/requirejs-text/t
ext","jquery":"bower_components/jquery/jquery"}, shim={"backbone":{"exports":"Backbone","deps":["underscore","jquery"]},"underscore":{"exports":"_"},"handlebars":{"exports":"Handlebars"}}, modules=[{"name":"app","include":["aura","jquery"]}], onBuild
Write=undefined
>> Tracing dependencies for: app

从这个输出看来,未定义完成函数,但我确实定义了它,我甚至使用了grunt-contrib-requirejs readme中的一个例子。

我正在使用grunt@0.4.1grunt-contrib-requirejs@0.4.1 requirejs@2.1.8。节点是版本v0.8.16

更新一个

我尝试升级我的节点,我现在在v0.10.17,但此处没有任何更改。

我从我的模块中删除了aura,它现在看起来像这样:

modules: [{
    name: "app",
    include: ["jquery"]
}],

这给了我更多的输入,但它仍然停止了我的Grunt,并且没有运行我的完成功能,我得到了这个输出:

>> app.js
>> ----------------
>> bower_components/aura/lib/platform.js
>> bower_components/aura/lib/base.js
>> bower_components/aura/lib/logger.js
>> bower_components/aura/lib/aura.extensions.js
>> bower_components/aura/lib/aura.js
>> app.js

3 个答案:

答案 0 :(得分:2)

问题是您的done功能失败,并且未设置grunt任务以将错误转发给您。我做了一个PR that you can look at here来解决这个问题。

答案 1 :(得分:1)

我在GitHub上发现了我的问题:https://github.com/gruntjs/grunt-contrib-requirejs/issues/37

但是还没有解决方案,我可能不得不亲自查看错误。

答案 2 :(得分:0)

如果从requireJS选项中删除整个“done”部分,它将不会暂停执行任务列表,但是您将无法对编译的代码执行分析