Yeoman生成器-angular的grunt serve:dist破坏了我的应用程序。

3

我使用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标签中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) {

我还在这个 gist中包含了 index.jade、app.js 和 main.js,以供进一步参考。如果需要更多信息来诊断此错误,请告知我,但我已尝试找到的所有修复方法都无效。感谢任何帮助。

1个回答

2
当您使用Yeoman创建应用程序时,Grunt文件和bower.json文件中可以包含模块名称。因此,请在Gruntfile.js的构建任务下查找,例如:
Gruntfile.js:
  372        dist: {
  373          options: {
  374:           module: 'sitesApp',

将“sitesApp”更改为您在Angular代码中调用应用程序的名称,例如“monopolyApp”。

我下次会尝试这个方法,但似乎问题出在生成器本身而不是我的代码上,因为当我尝试使用默认模板发布应用程序时,它给出了相同的错误。我所做的只是手动将我的stylus转换为css和jade转换为html,然后使用常规的generator-angular运行它,它完美地工作了。我会考虑将来使用这个方法。现在已经点赞,但我会在再次使用生成器并尝试它之后将其标记为正确答案。谢谢! - Elliot Tregoning

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接