Gathering detailed insights and metrics for iso-morphic-style-loader
Gathering detailed insights and metrics for iso-morphic-style-loader
Gathering detailed insights and metrics for iso-morphic-style-loader
Gathering detailed insights and metrics for iso-morphic-style-loader
npm install iso-morphic-style-loader
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
16 Stars
189 Commits
3 Watching
3 Branches
1 Contributors
Updated on 20 Nov 2023
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
5.8%
109
Compared to previous day
Last week
23.1%
549
Compared to previous week
Last month
-26%
2,055
Compared to previous month
Last year
-28.7%
33,902
Compared to previous year
3
7
The isomorphic style loader based on style-loader, work both with server side and browser side.
npm install iso-morphic-style-loader --save-dev
In fact, there is nothing different with the style-loader, just use the same config as you like.
However, some more work if you want to add critical path CSS with isomorphic app:
1/// Such as server.js, where you render your isomorphic app and will send it 2/// back to your user. 3data.styles = [] 4// iso-morphic-style-loader will offer you the way to access imported styles 5// via React's context. 6const context = { 7 // will be invoked when render in server side 8 iterateCss: (styles) => { 9 styles.forEach(style => { 10 data.push({ 11 ...style.attrs, 12 id: style.id, 13 cssText: style.content.join('\n') 14 }) 15 }) 16 }, 17} 18// Then we will pass this styles to your React Component. 19const html = ReactDOM.renderToStaticMarkup(<App {...data} />) 20res.status(route.status || 200) 21res.send(`<!doctype html>${html}`) 22 23/////////// 24 25// Here is your App.js 26// Perfect, we can insert styles easily. 27render() { 28 return ( 29 {styles.map(({id, cssText, ...rest}) => 30 <style 31 {...rest} 32 key={id} 33 id={id} 34 dangerouslySetInnerHTML={{ __html: cssText }} 35 /> 36 )} 37 ) 38} 39 40////////// 41// And here your component where really import styles 42import React from 'react' 43import PropTypes from 'prop-types' 44import notifyCssDeps from 'iso-morphic-style-loader/lib/notifyCssDeps' 45import css from './index.css' 46import css2 from './demo.css' 47 48// The decorator will invoke previous iterateCss method when the component get rendered 49@notifyCssDeps(css, css2) 50class MyComponent extends React.Component { 51 render() {} 52}
For server side, the lib will use React's context to offer you a way to access styles.
1iterateCss: (styles) => {
2 styles.forEach(style => {
3 data.push({
4 ...style.attrs,
5 id: style.id,
6 cssText: style.content.join('\n')
7 })
8 })
9}
Nothing will happens if you ignore iterateCss
, no errors in server side rendering, and works the same as style-loader
do.
But if you want to optimize for critical path CSS rendering, please inject styles during server side rendering.
The browser side behaviour is exactly the same as style-loader@0.18.2
. And you can enjoy all features supported by style-loader@0.18.2
.
No FOUC, no duplicate!
Left is with style-loader
and right is with iso-morphic-style-loader
.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
80 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
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