【问题标题】:Yeoman generator-angular grunt serve:dist breaks my appYeoman generator-angular grunt serve:dist 破坏了我的应用程序
【发布时间】:2016-04-21 06:53:13
【问题描述】:

我用 Yeoman 构建了一个应用程序,使用 generator-angular-jade-stylus,并且在使用 grunt serve 的开发版本中一切正常,在控制台中没有一个错误,但是在使用 grunt serve:dist 构建应用程序时,我的应用变成了一个空白页面,控制台出现以下错误:

66e3c8ac.vendor.js:4 Uncaught Error: 
Failed to instantiate module monopolyApp due to:
Error: [$injector:nomod] Module 'monopolyApp' is not available! You 
either misspelled the module name or forgot to load it. If registering 
a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.2.15/$injector/nomod?p0=mon...
    at http://localhost:9000/scripts/66e3c8ac.vendor.js:4:12729
    at http://localhost:9000/scripts/66e3c8ac.vendor.js:4:20410
    at b (http://localhost:9000/scripts/66e3c8ac.vendor.js:4:19993)
    at http://localhost:9000/scripts/66e3c8ac.vendor.js:4:20305
    at http://localhost:9000/scripts/66e3c8ac.vendor.js:4:27065
    at Array.forEach (native)
    at f (http://localhost:9000/scripts/66e3c8ac.vendor.js:4:13059)
    at k (http://localhost:9000/scripts/66e3c8ac.vendor.js:4:27005)
    at Fa (http://localhost:9000/scripts/66e3c8ac.vendor.js:4:28542)
    at e (http://localhost:9000/scripts/66e3c8ac.vendor.js:4:18649)

我的尝试

我对此错误进行了大量研究,并找到了一些修复方法,但没有一个对我有用...其中一个提到 useminPrepare 会缩小脚本,然后 uglify 会再次缩小脚本,破坏了脚本,他们说要从 useminPrepare 块中删除 uglify 来解决它。我试过这个,它只是给了我一个错误,它找不到 uglify 任务,然后中止了。

我发现了另一个修复程序,将 <!-- build:js scripts/vendor.js --> 更改为 <!-- build:js(app/..) scripts/vendor.js --><!-- build:js(./) scripts/vendor.js --> -- 使用此方法从控制台中删除了错误,但仍然给我留下了空白页。

我已将模块正确附加到主体 body(ng-app="monopolyApp"),这就是我的模块在 app.js 中的定义方式:

angular
  .module('monopolyApp', [
    'ngCookies',
    'ngResource',
    'ngSanitize',
    'ngRoute',
    'LocalStorageModule'
  ])

在控制器中(main.js)

angular.module('monopolyApp')
  .controller('MainCtrl', function ($scope, $window, $timeout, localStorageService) {

我还在this gist 中包含了 index.jade、app.js 和 main.js 以供进一步参考。如果需要任何进一步的信息来诊断此错误,请告诉我,但我已经尝试了所有可以找到的修复程序,但没有任何效果。任何帮助表示赞赏。谢谢!

【问题讨论】:

    标签: javascript angularjs gruntjs yeoman yeoman-generator-angular


    【解决方案1】:

    当您使用 Yeoman 创建应用程序时,它可以在您的 Grunt 文件和 bower.json 文件中包含模块名称。因此,请查看 Gruntfile.js 中的构建任务,例如:

    Gruntfile.js:
      372        dist: {
      373          options: {
      374:           module: 'sitesApp',
    

    将“sitesApp”更改为您在 Angular 代码中调用应用程序的任何内容,例如'垄断应用'

    【讨论】:

    • 下次我会试试这个,但这似乎是生成器本身的问题,而不是我的代码,因为当我尝试使用默认模板发布应用程序时它给出了同样的错误让你开始。我所做的只是将我的手写笔手动转换为 css 并将玉石转换为 html,然后使用常规的生成器角度运行它,它工作得很好。我会在未来考虑这个。暂时赞成,但是一旦我再次使用生成器并尝试一下,我就会将其标记为正确答案。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 2016-05-16
    • 2014-05-11
    • 2017-05-18
    • 1970-01-01
    • 2014-08-11
    相关资源
    最近更新 更多