【问题标题】:gulp bower - angular is not installedgulp bower - 未安装角度
【发布时间】:2017-05-19 08:53:04
【问题描述】:

我正在开始一个使用 Yeoman 生成的新 Angular 项目(第一次使用 gulp),但我遇到了一些问题(我认为这可能是相关联的)

  • 当我执行gulp serve 时,终端中没有错误,但 bower 似乎没有注入依赖项。在网络检查器中,我有:

    <!-- build:css(.) styles/vendor.css -->
    <!-- bower:css -->
    <!-- endbower -->
    <!-- endbuild -->
    
  • 当我执行gulp test 时,我在终端中收到此错误:

    PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
    ReferenceError: Can't find variable: angular
    at /Applications/MAMP/htdocs/gulp_test/app/scripts/app.js:11
    
  • gulp bower 时出现同样的错误

谁能帮我解释一下为什么它不起作用?

编辑:刚刚意识到我在做gulp serve的网络检查器中仍然存在角度错误

【问题讨论】:

  • grunt serve 上浏览器会自动打开吗?
  • 感谢您的回复。不,它没有,但我可以在 localhost:8080 打开浏览器,它似乎可以工作(除了那个错误)
  • 如果你使用 gulp,你为什么输入grunt serve
  • 对不起,我的错。输入错误。我改正了

标签: javascript angularjs gulp bower


【解决方案1】:

所以我昨天在这方面做了一些工作,我终于发现了。

对于 gulpfile.js,删除“/views”,因为目标必须是您的整个应用,而不仅仅是视图:

gulp.task('bower', function () {
  return gulp.src(paths.views.main)
  .pipe(wiredep({
directory: yeoman.app + '/bower_components',
    ignorePath: '..'
}))

.pipe(gulp.dest(yeoman.app) <s>+ '/views'</s>);

});  

在 .bowerrc 中,我将 bower_components 的路径更改为 app/bower_components

我已更改所有连接功能(添加中间件部分):

$.connect.server({
   root:['\.tmp', yeoman.app],
   livereload:true,
   port: 9000,
   middleware:function(connect, opt){
     return [['/bower_components', 
     connect["static"]('./bower_components')]]
   }
});

bower install 之后,它就像一个魅力。 我在这里找到了这个解决方案:https://github.com/yeoman/generator-angular/issues/1295

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-02
    • 1970-01-01
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多