Gathering detailed insights and metrics for @someonewithpc/scoped-css-loader
Gathering detailed insights and metrics for @someonewithpc/scoped-css-loader
Gathering detailed insights and metrics for @someonewithpc/scoped-css-loader
Gathering detailed insights and metrics for @someonewithpc/scoped-css-loader
npm install @someonewithpc/scoped-css-loader
Typescript
Module System
Node Version
NPM Version
JavaScript (94.47%)
SCSS (5.53%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
464 Stars
112 Commits
39 Forks
3 Watchers
5 Branches
5 Contributors
Updated on Jun 08, 2025
Latest Version
1.2.0
Package Id
@someonewithpc/scoped-css-loader@1.2.0
Unpacked Size
7.52 kB
Size
3.01 kB
File Count
8
NPM Version
lerna/6.6.2/node@v19.9.0+x64 (linux)
Node Version
19.9.0
Published on
May 24, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
CSS encapsulation solution for React
In order to solve the problem of css encapsulation, there are two main approaches, css-modules and css-in-js. However, both of them have a very very big problem. The developer experience is not good, by which I mean you often have to write more code than you expect to achieve a simple style. With react-scoped-css, you can just write the normal css you know, while having the advantage of css encapsulation!
Write your css in a file ends with .scoped.css
(scss
& sass
are also supported)
1/* Title.scoped.css */ 2.title { 3 background: #999; 4} 5 6p { 7 color: #ddd; 8}
Import the css file
1// Title.jsx 2import React from 'react' 3import './Title.scoped.css' 4 5const Title = (props) => { 6 return ( 7 <h1 className="title"> 8 <p>{props.children}</p> 9 </h1> 10 ) 11} 12 13export default Title
Then, in the html, component with scoped css file imported has a unique data-v-<hash>
attribute on the html element tag, and the css selector also has a corresponding hash like selector[data-v-<hash>]
. So all the styles in Title.scoped.css
are scoped to Title.jsx
.
Since create-react-app doesn't allow you to change webpack and babel config. So in this scenario, you have to use craco to override webpack config. Luckily you don't have to do it manually, I created a craco plugin that can do it for you.
Setup craco following this guide
Then, install craco-plugin-scoped-css
yarn add craco-plugin-scoped-css
create a craco.config.js
in your project root
1module.exports = { 2 plugins: [ 3 { 4 plugin: require('craco-plugin-scoped-css'), 5 }, 6 ], 7}
You have to add one babel plugin and one webpack loader.
the babel plugin
yarn add babel-plugin-react-scoped-css --dev
and in your babelrc add
1"plugins": ["babel-plugin-react-scoped-css"]
also note that you can define your own matching rule like this
1"plugins": [ 2 [ 3 "babel-plugin-react-scoped-css", 4 { 5 "include": ".local.(sa|sc|c)ss$" 6 } 7 ] 8]
If you have other plugins installed, just add it to the list, order doesn't matter.
Note: this plugin accepts include
(RegExp, which defaults to /\.scoped\.(sa|sc|c)ss$/
) to config which css file to be identified as scoped.
the webpack loader
yarn add scoped-css-loader --dev
and in your webpack.config.js
1{ 2 test: /\.(sc|c|sa)ss$/, 3 use: [ 4 { 5 loader: 'style-loader', 6 }, 7 { 8 loader: 'css-loader', 9 options: { 10 sourceMap: true, 11 importLoaders: 2, 12 }, 13 }, 14 // You have to put in after `css-loader` and before any `pre-precessing loader` 15 { loader: 'scoped-css-loader' }, 16 { 17 loader: 'sass-loader', 18 }, 19 ], 20},
That's it for the configuration.
Check out simple-scoped-css-example
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
Found 4/17 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
52 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More