javascript - Requirejs:dist 失败,Loader 插件没有在 build:text 中调用加载回调

标签 javascript requirejs gruntjs yeoman requirejs-text

我正在使用 yeoman,grunt 构建在 requirejs:dist 处失败,并出现错误“Loader 插件未在构建中调用加载回调:文本”。

我看到了问题here但更新 requirejs 对我没有帮助。控制台输出如下:

    PS D:\...> bower -version
    1.2.7
    PS D:\...> npm -version
    1.3.11
    PS D:\...> bower ls
    bower check-new     Checking for new versions of the project dependencies..
    html-console#0.0.0 D:\...
    +-- backbone#1.1.0
    +-- bootstrap#3.0.1
    ¦ +-- jquery#2.0.3
    +-- jquery#2.0.3
    +-- modernizr#2.6.2
    +-- requirejs#2.1.9
    +-- requirejs-text#2.0.10
    +-- sass-bootstrap#3.0.1
    ¦ +-- jquery#2.0.3
    +-- underscore#1.5.2
    PS D:\...> npm ls | grep require
    ????????? grunt-bower-requirejs@0.7.1
    ??? ????????? requirejs@2.1.9
    ????????? grunt-requirejs@0.4.0
    ??? ????????? requirejs@2.1.9
    PS D:\...> grunt build
    Running "clean:dist" (clean) task
    Cleaning .tmp...OK

    Running "coffee:dist" (coffee) task

    Running "coffee:test" (coffee) task

    Running "createDefaultTemplate" task

    Running "jst:compile" (jst) task
    >> Destination not written because compiled files were empty.

    Running "compass:dist" (compass) task
    directory .tmp/styles/
       create .tmp/styles/login-reg.css (0.029s)
       create .tmp/styles/main.css (1.796s)
    Compilation took 1.83s

    Running "useminPrepare:html" (useminPrepare) task
    Going through app/index.html to update the config
    Looking for build script HTML comment blocks

    Found a block:
            <!-- build:css(.tmp) styles/main.css -->
            <link rel="stylesheet" href="styles/main.css">
            <link rel="stylesheet" href="styles/login-reg.css">
            <!-- endbuild -->
    Updating config with the following assets:
        - .tmp\styles\main.css
        - .tmp\styles\login-reg.css

    Found a block:
            <!-- build:js scripts/vendor/modernizr.js -->
            <script src="bower_components/modernizr/modernizr.js"></script>
            <!-- endbuild -->
    Updating config with the following assets:
        - app\bower_components\modernizr\modernizr.js

    Found a block:
            <!-- build:js scripts/main.js -->
            <script data-main="scripts/main" src="bower_components/requirejs/require.js"></script>
            <!-- endbuild -->
    Updating config with the following assets:
        - dist\scripts\main.js

    Configuration is now:

      cssmin:
      { dist:
       { files:
          { '<%= yeoman.dist %>/styles/main.css':
             [ '.tmp/styles/{,*/}*.css',
               'app/styles/{,*/}*.css' ] } },
      'dist\\styles\\main.css': 'dist\\styles\\main.css' }

      concat:
      { 'dist\\styles\\main.css':
       [ '.tmp\\styles\\main.css',
         '.tmp\\styles\\login-reg.css' ],
      'dist\\scripts\\vendor\\modernizr.js': [ 'app\\bower_components\\modernizr\\modernizr.js' ],
      'dist\\scripts\\main.js': [ 'dist\\scripts\\main.js' ] }

      uglify:
      { 'dist\\scripts\\vendor\\modernizr.js': 'dist\\scripts\\vendor\\modernizr.js',
      'dist\\scripts\\main.js': 'dist\\scripts\\main.js',
      'dist\\bower_components\\requirejs\\require.js': 'app\\bower_components\\requirejs\\require.js' }

      requirejs:
      { dist:
       { options:
          { baseUrl: 'app/scripts',
            optimize: 'none',
            paths: { templates: '../../.tmp/scripts/templates' },
            preserveLicenseComments: false,
            useStrict: true,
            wrap: true,
            name: 'main',
            out: 'dist\\scripts\\main.js',
            mainConfigFile: 'app\\scripts\\main.js' } } }

    Running "requirejs:dist" (requirejs) task
    >> Error: Error: Loader plugin did not call the load callback in the build: text
    >> Module loading did not complete for: main, app, router, views/users/register, text!/templates/unauthd/register.html,
    views/users/forgotpassword, text!/templates/unauthd/forgotpassword.html
    >> The following modules share the same URL. This could be a misconfiguration if that URL only has one anonymous module
    in it:
    >> undefined: text!/templates/unauthd/register.html, text!/templates/unauthd/forgotpassword.html
    >>     at Function.build.checkForErrors (D:\...\node_modules\grunt-requirejs\node_modules\requirejs\bin\r.js:25510:19)
    Warning: Task "requirejs:dist" failed. Use --force to continue.

    Aborted due to warnings.

    Elapsed time
    loading tasks       2s
    jst:compile         24ms
    compass:dist        2s
    useminPrepare:html  63ms
    requirejs:dist      528ms
    Total               5s
    PS D:\...>

最佳答案

r.js 2.1.10 版本改进了错误报告。您可能会像我一样发现您的补充 HTML 文件(register.html 和忘记密码.html)没有像您希望的那样复制到 .tmp。我现在正在解决配置问题,但是让主干 View 加载没有替换的 ejs 可能更容易。

关于javascript - Requirejs:dist 失败,Loader 插件没有在 build:text 中调用加载回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19813595/

相关文章:

node.js - 如何在 node.js 中手动安装 grunt.js?

javascript - 使用 globbing 模式时 grunt-contrib-concat 的奇怪行为

javascript - 构建 Angular 叉失败

javascript - 如何为 jQuery 中的每个数组元素附加不同的动画效果?并使用 2 个按钮(下一个)一个一个地向前和向后设置动画?

雪花过程中的Javascript数组

javascript - Require.js 加载应用程序的所有资源,包括 Polymer

javascript - RequireJS: 模块名称 __ 尚未加载上下文,但仅针对某些,而不是全部

jquery - 如何将 jQuery ajaxPrefilter 方法应用于所有 require.js View ?

用于带 SSL 的 Restful Web 服务的 JavaScript 客户端

javascript - 引用数据类型 javascript