将聚合物1.0与3.0结合 [英] Combining polymer 1.0 with 3.0

查看:97
本文介绍了将聚合物1.0与3.0结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在修改聚合物1.0中内置的现有项目.

I am working on modifying an existing project which is built in polymer 1.0.

由于聚合物的当前版本是聚合物3.0,我们如何在不对现有应用程序进行太多更改的情况下将其包含在内.

As the current version of polymer is polymer 3.0 how can we include the same without making much changes with the existing application.

与我发现的主要区别在于,导入了聚合物1.0 .html文件,而导入了聚合物3.0 .js文件.

The main difference than i found out is that in polymer 1.0 .html files are imported whereas in polymer 3.0 .js files are imported.

在两个进口之间的比较下面添加了

Added below the comparison between two imports

<head>
<link rel="import" href="../../bower_components/polymer/polymer-element.html">
</head>

聚合物3

import {PolymerElement, html} from '@polymer/polymer';

当我们尝试安装组件时,将创建js文件.有什么方法可以通过CLI创建旧类型的聚合物组件?

When we try to install components js files are being created. Is there any method to create old type polymer components via CLI?

推荐答案

我认为您不应该尝试在 HTML 文件中将 Polymer 3 元素创建为HTML导入不受支持(例如在FF中)或即将过期(例如在Chrome中),如您所见,

I don't think you should try to create Polymer 3 elements in HTML files, as HTML imports are either not supported (in FF, for example), or about to become obsolete (in Chrome, for example), as you can see here.

使用Polymer 1.x/2.x(带有HTML导入)和 Polymer 3.x 和/或 LitElement 创建的组件之间必须混合使用 webpack 构建步骤,该步骤将捆绑所有JS文件. (例如,只有一个JS文件,您可以在其中导入新元素,通过webpack传递它并将其包含在Polymer 1.x应用程序中.)

A mix between components crated with Polymer 1.x/2.x (with HTML imports) and Polymer 3.x and/or LitElement would be to have an webpack build step, that would bundle all the JS files. (for example have a single JS file where you import your new elements, pass it throgh webpack and include it in your Polymer 1.x app).

但是从长远来看,从HTML导入迁移 似乎是更安全的选择.您可能想看看@HakanC建议的调制器.

But in the long run migrating away from HTML imports seems like the safer bet. You might want to take a look at the modulizer, as @HakanC suggested.

这篇关于将聚合物1.0与3.0结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆