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

react-scoped-css-loaders

v1.0.12

Published

react css scoped style-components

Downloads

24

Readme

基于 React Scope css 方案

背景

在之前的代码习惯中很多布局都是比较相近的词汇,比如左侧 header,body,foot, 右侧也是 header,body,foot,如果使用 css Modal 的话,由于是扁平化的 key 那么我的 body 就不能确定是当前的 body 属性了,于是想像 vue 一样写,目前没有发现问题如果有问题 联系我哦[email protected]

umijs 引用


...
  chainWebpack(memo, { env, webpack, createCSSRule }) {
    memo.module
      .rule('util-loader')
      .test(/\.tsx$/)
      .exclude.add([
        path.resolve('./src/.umi'),
        path.resolve('./src/pages/.umi'),
        path.resolve('node_modules'),
      ])
      .end()
      .use('react-scoped-css-loaders')
      .loader('react-scoped-css-loaders');
  },

...

其他 webpack 参考 umijs 一样的就不写 demo 了哦

使用

  • style-components 的组件名称使用 scoped_css 结尾就行
import { useState } from "react";
import styled from "styled-components";
const WarpBody_scoped_css = styled.div`
  background-color: red;
  .title {
    background-color: red;
  }
  .page {
    background-color: red;
    .title {
      font-size: 16px;
    }
    .kkk {
      color: yellow;
    }
    .body {
      color: red;
    }
    .a {
      .body {
        color: red;
      }
    }
    .b {
      .body {
        color: red;
      }
    }
  }
  .selected {
    color: yellow;
  }
`;

const Page = () => {
  const [state, setState] = useState({
    list: new Array(10).fill(10),
  });
  return (
    <WarpBody_scoped_css>
      <div className={["page", 1 === 2 ? "selected" : ""].join(" ")}>
        <h1 id="13" className="title kkk">
          Page index
        </h1>
        <div className="a">
          <div className="body">
            {state.list.map((curr) => {
              return <div className="item">123123</div>;
            })}
          </div>
        </div>
        <div className="b">
          <div className="body"></div>
        </div>
      </div>
    </WarpBody_scoped_css>
  );
};

export default Page;

输出内容

import * as React from "react";
import { useState } from "react";
import styled from "styled-components";
const WarpBody_scoped_css = styled.div`
  background-color: red;
  .title_nzr4bvxwhm9 {
    background-color: red;
    &:hover {
      color: red;
    }
  }
  .page_69gqcmc3flg {
    background-color: red;
    .title_z8596k3fs9d {
      font-size: 16px;
    }
    .kkk_advufwy9l2t {
      color: yellow;
    }
    .body_y4n5sko7rmd {
      color: red;
    }
    .a_ajrnwmdtqzh {
      .body_wgw9hea428d {
        color: red;
      }
    }
    .b_zdfpa9sdorr {
      .body_upz6zssbmba {
        color: red;
      }
    }
  }
  .selected_yki6w7abcx {
    color: yellow;
  }
`;

const Page = () => {
  const [state, setState] = useState({
    list: new Array(10).fill(10),
  });
  return (
    <WarpBody_scoped_css>
      <div></div>
      <div
        className={[
          "page_69gqcmc3flg",
          1 === 2 ? "selected_yki6w7abcx" : "",
        ].join(" ")}>
        <h1
          id="13"
          className="title_nzr4bvxwhm9 title_z8596k3fs9d kkk_advufwy9l2t">
          Page index
        </h1>
        <div className="a_ajrnwmdtqzh">
          <div className="body_y4n5sko7rmd body_wgw9hea428d">
            {state.list.map((curr) => {
              return <div className="item">123123</div>;
            })}
          </div>
        </div>
        <div className="b_zdfpa9sdorr">
          <div className="body_y4n5sko7rmd body_upz6zssbmba"></div>
        </div>
      </div>
    </WarpBody_scoped_css>
  );
};

export default Page;