简体   繁体   English

在Bower中使用自定义聚合物元素

[英]Using custom polymer elements in with bower

I've got a custom Polymer element polymer install element call it <x-custom-element> once created i'm unable to polymer serve until I change the links to reference the bower components in the elements folder. 我创建了一个自定义的Polymer元素Polymer polymer install element称为<x-custom-element>一旦创建,我将无法polymer serve直到我更改链接以引用elements文件夹中的Bower组件。

When I publish the element to my git repository I need to change the references in the elements <links rel="import" href="bower_components/"> to href="../` or what ever the link is to use the bower_components folder form the directory that install the element. 当我将元素发布到git仓库时,我需要将元素<links rel="import" href="bower_components/"> to的引用更改<links rel="import" href="bower_components/"> to href =“ ../`或使用bower_components的链接文件夹形成安装元素的目录。

For example to be able to serve the file via polymer serve , with this file structure 例如,可以通过具有这种文件结构的polymer serve提供文件

  • bower.json bower.json
  • bower_components/ bower_components /
  • test/ 测试/
  • temo/ 特莫/
  • x-custom-element.html x-custom-element.html

The links in x-custom-element.html need to refer to /bower_components/* x-custom-element.html的链接需要引用/bower_components/*

But to be able to be usable as a bower import I must change the references to ../* 但是要能够用作凉亭导入,我必须将引用更改为../*

Is there anyway to remedy this process? 无论如何,有没有补救措施? How should you approach this problem. 您应该如何解决这个问题。

Create a script to change all the link back and forth? 创建脚本来来回更改所有链接? What other options do I have? 我还有什么其他选择?

Your example project directory is missing index.html in the root. 您的示例项目目录的根目录中缺少index.html This should be automatically generated by polymer-cli (ie, polymer init element ), and it should look like this: 这应该由polymer-cli (即, polymer init element )自动生成,并且应如下所示:

<!doctype html>

<html>
  <head>
    <title>x-foo</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../webcomponentsjs/webcomponents-lite.js"></script>
    <link rel="import" href="../iron-component-page/iron-component-page.html">
  </head>
  <body>
    <iron-component-page src="x-foo.html"></iron-component-page>
  </body>
</html>

I didn't have any problems viewing the site with polymer serve -o after generating the element project with polymer init element ( polymer-cli v0.16.0, polyserve v0.13.0, macOS Sierra 10.12). 在使用polymer init elementpolymer-cli v0.16.0, polyserve v0.13.0,macOS Sierra 10.12)生成元素项目后,使用polymer serve -o查看站点没有任何问题。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM