【问题标题】:grunt-contrib-requirejs task stops Grunt without errorsgrunt-contrib-requirejs 任务停止 Grunt 而没有错误
【发布时间】:2013-08-23 12:05:29
【问题描述】:

我有一个问题,我的grunt-contrib-requirejs 任务停止了我的 grunt 进程。它完全没有错误地做到这一点。我需要帮助确定问题。

我的总体任务

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

从这个输出看来,done 函数没有定义,但我确实定义了它,我什至使用了来自grunt-contrib-requirejs readme 的示例。

我将grunt@0.4.1grunt-contrib-requirejs@0.4.1requirejs@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

【问题讨论】:

  • 我会尝试 2 件事来尝试找出问题所在: 1. 根据this example,在我看来,您设置了错误的基本 URL。它应该是 'app/' 2. 尝试将您对 requirejs 的选项浏览到最低限度,看看它是否仍然没有运行。我猜想目前它停留在为您的应用 app 定位依赖项上。试试这些,我们看看还能做什么
  • 我尝试了这两种方法,但没有运气 - 仍然是相同的输出。
  • 我从我的包含中删除了aura,它现在似乎可以工作,至少找到依赖项,但之后它停止了我的咕噜声并且不运行我的完成功能。

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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    但目前还没有解决方案,我可能需要自己查看错误。

    【讨论】:

      【解决方案3】:

      如果您从 requireJS 选项中删除整个“完成”部分,它不会停止任务列表的执行,但是您将失去对已编译代码执行分析的能力

      【讨论】:

      • 这就是我所做的,但通过解决方案,我希望它能够工作而不仅仅是删除它。它仍然不工作,我没有时间看它。
      猜你喜欢
      • 2018-02-13
      • 1970-01-01
      • 2014-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-25
      相关资源
      最近更新 更多