Build 如何使用聚合物2构建过程?

Build 如何使用聚合物2构建过程?,build,polymer-2.x,polymer-cli,Build,Polymer 2.x,Polymer Cli,我知道这可能是一个复制品,但从来没有明确的答案 到目前为止,Polymer 2框架有一个相当好的文档,但是当涉及到构建过程时,没有足够的解释 我已经成功地创建了自己的元素,还引用了外部脚本,并且一切都可以正常运行 polymer serve --open 但是我花了太多时间来构建它,并将输出包含到一个最小的HTML模板中,但没有成功。真的有那么棘手吗 我甚至用空元素模板再试了一次,没有机会。此模板有一个近乎空白的polymer.json: { "lint": { "ru

我知道这可能是一个复制品,但从来没有明确的答案

到目前为止,Polymer 2框架有一个相当好的文档,但是当涉及到构建过程时,没有足够的解释

我已经成功地创建了自己的元素,还引用了外部脚本,并且一切都可以正常运行

polymer serve --open
但是我花了太多时间来构建它,并将输出包含到一个最小的HTML模板中,但没有成功。真的有那么棘手吗

我甚至用空元素模板再试了一次,没有机会。此模板有一个近乎空白的polymer.json:

{
    "lint": {
        "rules": [
            "polymer-2"
        ]
    }
}
如果我马上用

polymer build 
(应该使用默认构建行为)然后我得到一个默认构建文件夹,其中包含index.html和bower_components文件夹。没有引用我创建的自定义元素(“Hello…”)


要获得此“Hello Something”模板的最终版本并将其包含到最小的html页面中,我必须做些什么?

Re
polymer build
“此命令仅适用于应用程序项目。”()


此外,还需要
shell
。请参阅。

有很多不同的方法可以使用单个组件从一个组件转到另一个应用程序,我不会说100%这是最好的,但它应该可以工作。“我该怎么做才能得到这个“Hello Something”模板的最终版本,并将其包含到一个最小的html页面中?”,这是一个非常灵活的请求,因此即使在下面的示例中,您也可以有很多选择,但下面是我的建议。我们将从命令行开始,从桌面或保存项目的文件夹开始

mkdir minimal-html-page
cd minimal-html-page
polymer init
// here make sure you choose `polymer-2-application` other questions re of little consequence in this specific use case
bower install {yourComponent} --save
// in that case that you haven't published to github, copy and paste also works. Paste into the `src` directory if that's the case.
atom .
// or whatever editor you prefer

现在你已经进入了你的项目,只需要一个改变就能让你继续

index.html

更改当前HTML导入

<link rel="import" href="/src/build-test-app/build-test-app.html">
这是最基本的构建,不会考虑项目中可能存在的任何x-browser或性能目标。您还将在
build/default
目录中看到需要复制/粘贴的所有文件,以便在其他地方使用该组件


如果您确实对x-browser抱有期望,那么可以通过使用
polymer build--compile
命令相当轻松地解决这些问题。这将创建稍微复杂一点的嵌入代码来管理ES5/6能力边界的任意一侧,看起来像:

<script>!function(e){var r=e.babelHelpers={};r.typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r.classCallCheck=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},r.createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),r.defineEnumerableProperties=function(e,r){for(var t in r){var n=r[t];n.configurable=n.enumerable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,t,n)}return e},r.defaults=function(e,r){for(var t=Object.getOwnPropertyNames(r),n=0;n<t.length;n++){var o=t[n],i=Object.getOwnPropertyDescriptor(r,o);i&&i.configurable&&void 0===e[o]&&Object.defineProperty(e,o,i)}return e},r.defineProperty=function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e},r.extends=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},r.get=function e(r,t,n){null===r&&(r=Function.prototype);var o=Object.getOwnPropertyDescriptor(r,t);if(void 0===o){var i=Object.getPrototypeOf(r);return null===i?void 0:e(i,t,n)}if("value"in o)return o.value;var a=o.get;if(void 0!==a)return a.call(n)},r.inherits=function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)},r.instanceof=function(e,r){return null!=r&&"undefined"!=typeof Symbol&&r[Symbol.hasInstance]?r[Symbol.hasInstance](e):e instanceof r},r.newArrowCheck=function(e,r){if(e!==r)throw new TypeError("Cannot instantiate an arrow function")},r.objectDestructuringEmpty=function(e){if(null==e)throw new TypeError("Cannot destructure undefined")},r.objectWithoutProperties=function(e,r){var t={};for(var n in e)r.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},r.possibleConstructorReturn=function(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r},r.set=function e(r,t,n,o){var i=Object.getOwnPropertyDescriptor(r,t);if(void 0===i){var a=Object.getPrototypeOf(r);null!==a&&e(a,t,n,o)}else if("value"in i&&i.writable)i.value=n;else{var u=i.set;void 0!==u&&u.call(o,n)}return n},r.slicedToArray=function(){function e(e,r){var t=[],n=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(n=(a=u.next()).done)&&(t.push(a.value),!r||t.length!==r);n=!0);}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}return t}return function(r,t){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return e(r,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),r.taggedTemplateLiteral=function(e,r){return Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(r)}}))},r.temporalRef=function(e,r,t){if(e===t)throw new ReferenceError(r+" is not defined - temporal dead zone");return e},r.temporalUndefined={},r.toArray=function(e){return Array.isArray(e)?e:Array.from(e)},r.toConsumableArray=function(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r<e.length;r++)t[r]=e[r];return t}return Array.from(e)}}("undefined"==typeof global?self:global);</script>


<script>if (!window.customElements) { document.write('<!--'); }</script>
    <script type="text/javascript" src="/bower_components/webcomponentsjs/custom-elements-es5-adapter.js"></script>
    <!--! do not remove -->
<script src="/bower_components/webcomponentsjs/webcomponents-loader.js"></script>

<link rel="import" href="/src/build-test-app/build-test-app.html">
<build-test-app></build-test-app>

!函数(e){var r=e.babelHelpers={};r.typeof=“函数”==typeof Symbol&&“Symbol”==typeof Symbol.迭代器?函数(e){return typeof e}:函数(e){return e&“function”==typeof Symbol&&e.constructor==Symbol&&e!==Symbol.prototype?:typeof e},r.classCallCheck=函数(e,r){if(!(e instanceof r))抛出新类型错误(“无法将类作为函数调用”)},r.createClass=function(){function e(e,r){for(var t=0;tOkay,所以如果我创建一个这样的单元素项目:上面的文章也缺少了从已开发元素到生产使用的部分。我现在不想用polymer构建我的整个应用程序。我只想在标准HTML文档中使用一个自定义元素。我需要在HTML文档中使用什么来实现自定义元素的工作呢g?你的意思是我不能构建/捆绑一个单一元素的项目?对不起,除了在组件及其HTML依赖项上复制的暴力过程外,我不知道还有什么。我读过一个Webpack插件()但没有使用它。你可以试着在推特上向“AskPolymer”发问这就是我一直在寻找的!我仍然不知道为什么单元素模板不起作用。这个名称对于刚接触框架的开发人员来说是非常容易误导和混淆的。对我来说,构建过程现在也可以通过预设构建配置和ad正常工作传统的外部依赖关系。您好,我想知道您是否找到了优化生产元素的解决方案?
<script>!function(e){var r=e.babelHelpers={};r.typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r.classCallCheck=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},r.createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),r.defineEnumerableProperties=function(e,r){for(var t in r){var n=r[t];n.configurable=n.enumerable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,t,n)}return e},r.defaults=function(e,r){for(var t=Object.getOwnPropertyNames(r),n=0;n<t.length;n++){var o=t[n],i=Object.getOwnPropertyDescriptor(r,o);i&&i.configurable&&void 0===e[o]&&Object.defineProperty(e,o,i)}return e},r.defineProperty=function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e},r.extends=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},r.get=function e(r,t,n){null===r&&(r=Function.prototype);var o=Object.getOwnPropertyDescriptor(r,t);if(void 0===o){var i=Object.getPrototypeOf(r);return null===i?void 0:e(i,t,n)}if("value"in o)return o.value;var a=o.get;if(void 0!==a)return a.call(n)},r.inherits=function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)},r.instanceof=function(e,r){return null!=r&&"undefined"!=typeof Symbol&&r[Symbol.hasInstance]?r[Symbol.hasInstance](e):e instanceof r},r.newArrowCheck=function(e,r){if(e!==r)throw new TypeError("Cannot instantiate an arrow function")},r.objectDestructuringEmpty=function(e){if(null==e)throw new TypeError("Cannot destructure undefined")},r.objectWithoutProperties=function(e,r){var t={};for(var n in e)r.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},r.possibleConstructorReturn=function(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r},r.set=function e(r,t,n,o){var i=Object.getOwnPropertyDescriptor(r,t);if(void 0===i){var a=Object.getPrototypeOf(r);null!==a&&e(a,t,n,o)}else if("value"in i&&i.writable)i.value=n;else{var u=i.set;void 0!==u&&u.call(o,n)}return n},r.slicedToArray=function(){function e(e,r){var t=[],n=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(n=(a=u.next()).done)&&(t.push(a.value),!r||t.length!==r);n=!0);}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}return t}return function(r,t){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return e(r,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),r.taggedTemplateLiteral=function(e,r){return Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(r)}}))},r.temporalRef=function(e,r,t){if(e===t)throw new ReferenceError(r+" is not defined - temporal dead zone");return e},r.temporalUndefined={},r.toArray=function(e){return Array.isArray(e)?e:Array.from(e)},r.toConsumableArray=function(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r<e.length;r++)t[r]=e[r];return t}return Array.from(e)}}("undefined"==typeof global?self:global);</script>


<script>if (!window.customElements) { document.write('<!--'); }</script>
    <script type="text/javascript" src="/bower_components/webcomponentsjs/custom-elements-es5-adapter.js"></script>
    <!--! do not remove -->
<script src="/bower_components/webcomponentsjs/webcomponents-loader.js"></script>

<link rel="import" href="/src/build-test-app/build-test-app.html">
<build-test-app></build-test-app>