首页 文章

用于角聚合物的Yeoman / Grunt发生器

提问于
浏览
0

我尝试使用AngularJS和Polymer(我实际上使用AngularJS作为服务,例如Token Auth和Polymer for Material Design)所以我想问一个简单的方法来为这种类型的App构建scafolding(Polymer AngularJS - 使用grunt运行localhost) )?我安装时的那一刻:

yo angular MyApp

我在根目录中有bower_components,如果我尝试通过以下方式安装Polymer:

bower install --save Polymer/polymer

所以我在AngularJS bower_components中安装了Polymer,(如果我使用yo聚合物生成器,bower_components文件夹位于/ root / app /文件夹中而不在其中)当我使用grunt服务时,我得到错误(示例与核心 - 工具栏):

core-toolbar was not injected in your file.
 Please go take a look in "/project-root/bower_components/core-component-page" for the file you need, then manually include it in your file.

所以我认为我需要改变Gruntfile.js中的内容,但我不知道是什么!也许最好使用两个bower_components文件夹?

1 回答

  • 0

    我解决了问题,所以我使用AngulaJS Generator for Yeoman,之后我将文件夹bower_components从/ project_root文件夹移动到/ project_root / app文件夹,所以我使用bower_components文件夹的新路径修改了.bowerrc文件:

    {
        "directory": "app/bower_components"
     }
    

    所以现在我可以使用bower来安装我需要的Polymer元素,像往常一样使用bower:

    bower install Polymer/core-toolbar
    

    我不使用--save来保存包中的依赖项,因为当grunt / bower尝试在index.html文件中插入链接时它会失败,所以从bower.json文件中删除Polymer依赖项并手动添加它们,其他提示删除了由grunt / bower在index.html文件中添加的关于聚合物的链接,并添加了webcomponents.js:

    <!-- Polymer Section -->
     <script src="bower_components/webcomponentsjs/webcomponents.js"></script>
     <!-- My imports -->
     <link rel="import" href="bower_components/core-toolbar/core-toolbar.html">
    

相关问题