[英]How to include external script files for publishing custom Polymer element?
I have the following Polymer element with the following dependencies: 我有以下具有以下依赖性的Polymer元素:
box-el
and player-el
other Polymer elements box-el
和player-el
其他聚合物元素 GameController
and KeyboardInputManager
classes that are defined in external files, game_controller.js
. game_controller.js
中定义的GameController
和KeyboardInputManager
类。 The question is, how do I package and publish this element as stand-alone, so it is legitimate for customelements.io . 问题是,我如何打包和发布此元素为独立元素,因此对于customelements.io是合法的。
<link rel="import" href="../../bower_components/polymer/polymer.html">
<polymer-element name="soko-ban">
<template>
<link rel="stylesheet" href="soko-ban.css">
<template repeat="{{box in boxes}}">
<box-el model="{{box}}"></box-el>
</template>
<player-el model="{{player}}" id="character"></player-el>
</template>
<script>
(function () {
'use strict';
Polymer({
ready: function() {
var controller = new GameController();
this.player = model.player;
this.boxes = model.boxes;
var inputManager = new KeyboardInputManager();
});
})();
</script>
</polymer-element>
Note that, I know how to publish this element, I am asking how to include the listed dependencies, namely the other Polymer elements, that I have written, and the external script files. 请注意,我知道如何发布此元素,我在询问如何包括列出的依赖项,即我编写的其他Polymer元素以及外部脚本文件。
It's actually not that hard but you need to follow a few steps in a particular order. 实际上并不难,但是您需要按照特定的顺序执行一些步骤。
There are two issues I see here that need to be solved: 我在这里看到有两个问题需要解决:
If this is your only file so far use Git to grab the generator-element
or polymer-boilerplate
. 如果这是您到目前为止唯一的文件,请使用Git抓住
generator-element
或polymer-boilerplate
。 These are quickly becoming the standard for polymer element repository structure. 这些正迅速成为聚合物元素存储库结构的标准。 Replace the html file for the main element in either if these with yours.
如果其中的main元素替换为html文件,则将它们替换为您的HTML文件。
distribution article building & publishing article Bower & Polymer video 发行文章 建设与出版文章 Bower&Polymer视频
You will need to install your dependency element and reference them in your component. 您将需要安装依赖项元素,并在您的组件中引用它们。 Use a .bowerrc to determine where your dependencies will install to and use
bower install --save <dep1> <dep2>
to install them. 使用.bowerrc确定依赖项的安装位置,并使用
bower install --save <dep1> <dep2>
安装它们。 reference them after your polymer import like this - 在您的聚合物导入后像这样引用它们-
<link rel="import" href="../../bower_components/polymer/polymer.html"> <link rel="import" href="relative/path/to/my/first/bower/dependency"> <link rel="import" href="relative/path/to/my/second/bower/dependency">
Verify your dependencies get resolved and that your element works then pu. 验证您的依赖关系已解决,然后您的元素正常工作。 blish with the keyword 'web-components' in your bower.json (should already be there if you used
generator-element
or polymer-boilerplate
) 在bower.json中使用关键字'web-components'进行修饰(如果使用了
generator-element
或polymer-boilerplate
应该已经存在了)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.