简体   繁体   English

聚合和使用外部JavaScript库

[英]Polymer and working with external JavaScript Libraries

With Shadow DOM, I can easily use external CSS frameworks like bootstrap nicely and it will only apply to my scope which is nice (example here ). 使用Shadow DOM,我可以很容易地使用像bootstrap这样的外部CSS框架,它只适用于我的范围,这很好(例如这里 )。

However, this doesn't apply to JavaScript libraries as far as I know. 但是,据我所知,这不适用于JavaScript库。 If I, for example, need to work with jQuery on my web component, I basically make it available for entire page. 例如,如果我需要在我的Web组件上使用jQuery,我基本上可以将它用于整个页面。 What is the recommend way to work with external JavaScript libraries with Polymer? 使用Polymer的外部JavaScript库的推荐方法是什么? How should I handle cases where my web component (which is distributed through bower) needs one version of foo.js and the consumer needs another? 我应该如何处理我的Web组件(通过bower分发)需要一个版本的foo.js而消费者需要另一个版本的情况?

There is no JavaScript encapsulation solutions I know of. 我不知道有没有JavaScript封装解决方案。

  1. Check if js encapsulation solutions exist, eg check zonejs and alternatives. 检查是否存在js封装解决方案,例如检查zonejs和替代方案。
  2. You may do it yourself but this will require you to devote some time to it. 你可以自己做,但这需要你花一些时间。 Eg I've encapsulated Babel with with statement as shown here (not tested). 例如,我已经封装用巴贝尔with如图陈述这里 (未测试)。

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

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