Search code examples
javascripthtmlpolymerweb-component

Using Polymer web components with no package manager


I would like to add some web components to a static web page without using any package manager or JavaScript build whatsoever.

Based on https://www.webcomponents.org/introduction#how-do-i-use-a-web-component- I tried importing it with unpkg changing

<script type="module" src="node_modules/@polymer/paper-button/paper-button.js"></script>

to

<script type="module" src="https://unpkg.com/@polymer/paper-button/paper-button.js"></script>

But it fails because of unmet peer dependencies.

My question is: Is there a place where I can find pre-compiled self-containing web components that I can easily import in my app or if I don't want to set up a JS build I have to play the human package manager myself?


Solution

  • You can do that by appending ?module to the unpkg URL

     <script type="module" src="https://unpkg.com/@polymer/paper-button/paper-button.js?module"></script>