This is an optimized workflow for those implementing unbundled builds for web components. The goal is to provide the easiest integration for unbundled builds, made popular by CDNs in large organizations. You have to use yarn because it supports "flat": true, which is required for unbundling to work
Check out the advanced HTML file on rawgit to see what's happening. Your site hydrates based on finding tags that are undefined. You'd put these in your application or on a CDN and then the integration methodology is the same every time regardless of app!
This is a starting point to do a build. Here's how to fork and customize it to be your own:
git clone https://github.com/elmsln/unbundled-webcomponents.git this repocd unbundled-webcomponents/app to move into the directoryyarn add to add / install new elements or edit app/package.json directlyapp/dist/app.js or reference them in app/dist/index.htmlyarn install to install dependenciesyarn run build which will generate a build/app/dist/ folder to your server / app location<script src="./dist/build.js"></script> to the bottom of your app / CMS or review app/index.html or app/advanced.html for more complete examplesapp/polymer.json has a extraDependencies property that accepts GLOBs to match files / assets not going to be caught by the bundler. The bundler will find anythign directly referenced (like import "whatever.js";) but will miss dynamically created things such as style.css file references in the HTML of a component. Adding to this array the specific additional assets to include helps ensure that everything is included in the output of the bundler.
Wait... I didn't think this was a bundler?! Well, polymer.json happens to do unbundled builds. It is a bundler / compiler but we're leveraging it just for the compiling capabilites and multiple output targets it provides. As a result, it does have some bundler-isms like having to define additional assets to include in the output, though they are left unbundled as well :)
yarn add @lrnwebcomponents/h-a-ximport "@lrnwebcomponents/h-a-x/h-a-x.js"; to the app/src/app.js fileyarn run build, rename the app/dist/ folder to webcomponentssites/all/libraries/polymer build to keep things separateThis has a configuration of polymer.json, a format used by the polymer CLI in order to create 2 builds of your assets.
This uses the polymer CLI for the time being. Once other plugins are written to do in-place, unbundled file building we'll update but for now it does a great job and has no requirement on using polymer in your project as it's just for commandline.
The file in /build.js does feature detection in order to establish if this is an ESM capable platform or needs a different build at run time. This reduces the integration with your platform / CMS / application down to two lines of <script> tags. The 1st adds support for CDNs as well as an option for forceUpdate which if the browser can't serve the build.js file it will force the user to a page asking them to upgrade.
We feature detect import() which 90+% of traffic supports as of end of 2019 and inject ES module based <script type="module"> imports. From there we try and detect which polyfills are needed based on the platform.
It has been heavily battle tested and is used in production in mutliple domains and websites.
This approach was developed by Penn State and tested by The US National Archives for accuracy.
Content type
Image
Digest
Size
194.1 MB
Last updated
over 5 years ago
docker pull elmsln/unbundled-webcomponents