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

postcss-single-spa-scoped

v1.6.1

Published

PostCSS plugin for manipulating the CSS in a single-spa application to best achieve scoped CSS

Downloads

551

Readme

postcss-single-spa-scoped

PostCSS plugin for manipulating the CSS in a single-spa application to best achieve scoped CSS.

.foo {
  /* Input example */
}
#single-spa-application\\:\\@org\\/app-name .foo {
  /* Output example */
}

Why...

Typically in single page application frameworks (Vue, React, etc.), there is a stylesheet imported at the global level.

// main.ts file
import './style.css';

These styles are not scoped to any component! This is typically a good thing as it allows you to share styles; but global stylesheets are a problem when your application is nested inside a microfrontend architecture. Why is it a problem? Because typically "import './style.css'" is compiled by bundlers into javascript code which mounts that style sheet in the head element as a style tag.

That style you defined in your style.css file? "h1 { font-size: 100px }".. It's now affecting the whole page!

This plugin attemps to counteract that by following the single-spa recomendation and prefixing all of your compiled css selectors with an id "#single-spa-application//:...". This works (for the most part) because your application is nested inside a div that single-spa creates that has the aforementioned fancy id.

image

There's a catch

Sometimes your application has portals (html outside the body) like modals or popups. These will typically leave the boundary of the single-spa div. That global style you defined will now not effect that portal because your now prefixed selectors wont select it.

To address this we added a field, additionalSelectors, to our plugin options. We expect an array of strings that are valid css selectors. We will then scope each original selector to each of the additional selectors you've provided along with the single-spa-id scope.

For example, if your pass ["#my-dialog"], the output will be:

#single-spa-application\:\@app1 .pointer-events-none,
#my-dialog .pointer-events-none {
	pointer-events: none
}

This will help you address the portals issue! Give your portal an id and then add that id as an additional selector... now your portal will be selected.

Usage

Step 1: Install plugin:

npm install --save-dev postcss-single-spa-scoped

Step 2: Add the plugin to your config:

Vite

// postcss.config.cjs
export default {
    plugins: {
        "postcss-single-spa-scoped": {
          // appName: "app1",
          // additionalSelectors: ["#my-dialog"]
        }
    },
}

Plugin Options Type Definitions

type PluginOpts = {
    appName?: string;
    additionalSelectors?: string[];
}