【问题标题】:Grunt Build not working with Bower-installed componentsGrunt Build 不适用于 Bower 安装的组件
【发布时间】:2013-05-23 00:23:40
【问题描述】:

我正在尝试运行

grunt build

从由

创建的目录中
yo angular

我通过凉亭安装了 angular-ui-bootstrap。本地我需要添加

<script src="components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>

到我的 index.html 和

angular.module('app', ['ngResource', 'ngCookies', 'ui.bootstrap'])

到我的 app.js。但是,每次我尝试构建应用程序时都会出现此错误

错误:没有模块:ui.bootstrap 在错误() 在 /Users/nicholasshook/angular/pokerfund/angular_app/app/components/angular/angular.js:1104:17 在确保(/Users/nicholasshook/angular/pokerfund/angular_app/app/components/angular/angular.js:1045:38) 在模块(/Users/nicholasshook/angular/pokerfund/angular_app/app/components/angular/angular.js:1102:14) 在 /Users/nicholasshook/angular/pokerfund/angular_app/app/components/angular/angular.js:2768:24 在 Array.forEach (本机) 在 forEach (/Users/nicholasshook/angular/pokerfund/angular_app/app/components/angular/angular.js:131:11) 在 loadModules (/Users/nicholasshook/angular/pokerfund/angular_app/app/components/angular/angular.js:2764:5) 在 /Users/nicholasshook/angular/pokerfund/angular_app/app/components/angular/angular.js:2769:38 在 Array.forEach (本机) TypeError:无法读取未定义的属性“awesomeThings” 在空。 (/Users/nicholasshook/angular/pokerfund/angular_app/test/spec/controllers/main.js:20:17)

【问题讨论】:

  • 请显示你用来添加ui-bootstrap的bower命令
  • 凉亭安装角度引导
  • 我也尝试通过 bower.json 和 bower install fwiw 安装 angular-bootstrap
  • 我必须将 --save 添加到 bower install 以确保我们添加到项目 bower install 中的 bower_components --save angular-bootstrap

标签: angularjs yeoman gruntjs angular-ui-bootstrap


【解决方案1】:

如果您通过 bower 安装了 ui-bootstrap,您还需要更新您的 karma.conf.js 以使 grunt 测试通过。

在文件karma.conf.js中为ui-bootstrap-tpls.min.js添加一个条目:

// list of files / patterns to load in the browser
files = [
  JASMINE,
  JASMINE_ADAPTER,
  'app/components/angular/angular.js',
  'app/components/angular-mocks/angular-mocks.js',
  'app/components/angular-bootstrap/ui-bootstrap-tpls.js',
  'app/scripts/*.js',
  'app/scripts/**/*.js',
  'test/mock/**/*.js',
  'test/spec/**/*.js'
];

【讨论】:

    【解决方案2】:

    一些想法:

    1. 确认当您安装 bower 时,文件已从其存储库成功下载,实际上已添加到您在脚本标签中列出的位置的文件结构中,即components/angular-bootstrap/ui-bootstrap-tpls.min.js

    2. 确认您的脚本标签的正确顺序,即您的&lt;script src="components/angular-bootstrap/ui-bootstrap-tpls.min.js"&gt;&lt;/script&gt; 标签需要在您的&lt;script src="scripts/app.js"&gt;&lt;/script&gt; 之前列出。如果没有,这就解释了为什么 app.js 找不到模块 'ui.bootstrap'。

    希望其中之一对您有所帮助。我使用了bower install angular-bootstrap,没有任何问题。

    【讨论】:

    • 感谢您的回答 grunt build 对您有用吗?作为一个可怕的黑客,我只是将 angular-ui 和 angular-ui-bootstrap 放在我的脚本目录中的 lib 文件夹中
    【解决方案3】:

    或者,如果 karma.conf.js 不是罪魁祸首,请验证您添加的任何新库是否已在 grunt 的 build.config.js 下的 vendor_files 中注册。那是我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-11
      • 2015-03-05
      • 2016-09-05
      • 1970-01-01
      • 1970-01-01
      • 2014-11-19
      • 2012-12-19
      • 1970-01-01
      相关资源
      最近更新 更多