npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-plugin-shadow-shim

v1.0.2

Published

A babel plugin to helps complete apps to run inside a ShadowRoot, by automatically rewriting DOM code to look inside the shadow root.

Downloads

313

Readme

babel-plugin-shadow-shim

This is a babel plugin that enables complete apps to run inside a shadow root.

The problem

A web application typically relies on a large number of DOM queries to work correctly. These queries are often called from the document node, since it's the root node. So if you try to stick the application inside of a shadow root, you have a problem: The DOM queries called from the document node will not reach inside the shadow root and the app will not be able to find the elements it expects.

Now, you could of course rewrite your application to look inside the shadow root instead. But what if it sometimes lives outside of a shadow root and sometimes not? You would have to write logic to determine this. Or what if you have third party dependencies that run DOM queries from the document node? This is where you typically reach the conclusion that Shadow DOM is more trouble than its worth.

The solution

So enter babel-plugin-shadow-shim! A babel plugin that solves the problem by rewriting DOM calls, for example document.querySelector, so that they instead gets called on the shadow root. If the specified shadow root does not exist, the calls are routed to document instead like they would normally.

Installation and configuration

Install from NPM:

$ npm install --save-dev babel-plugin-shadow-shim

Then add the plugin and settings to your .babelrc plugins section:

"plugins": [
  [
    "shadow-shim",
    {
    "shadowRootSelector": "#shadow",
    "appIdentifier": "myUniqueId",
    "debug": true
    }
  ]
]

shadowRootSelector is the selector of the element to which the shadow root is attached. Without this setting the plugin will not work.

appIdentifier can be any random string, and is used to make sure the code the plugin generates is unique to this application and does not conflict with other instances of babel-plugin-shadow-shim on the same page.

debug adds some logging to the console. Omit this option to avoid spamming your build logs!

Make sure that your pipeline is set up so that babel runs at the last stage. You want the plugin to process all the output javascript.

If you are using Angular CLI, you can set up babel separately and execute it as a post build step using the babel CLI.

NOTE:

  • This plugin is a work in progress. It's functionality is still very limited and there are problably bugs.