Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
I

isomorphic-style-loader

> 编程语言
Open source

CSS style loader for Webpack that is optimized for isomorphic (universal) web apps.

1.3K stars0 likes1 views
WebsiteGitHub

About

CSS style loader for Webpack that is optimized for isomorphic (universal) web apps.

Isomorphic CSS style loader for Webpack

CSS style loader for Webpack that works similarly to style-loader, but is optimized for critical path CSS rendering and also works great in the context of isomorphic apps. It provides two helper methods on to the styles object - ._insertCss() (injects CSS into the DOM) and ._getCss() (returns a CSS string).

See getting started  |  changelog  |  Join #isomorphic-style-loader chat room on Discord to stay up to date

How to Install

bash
$ npm install isomorphic-style-loader --save-dev

Requirements

  • Webpack 5
  • React 16.8 or newer
  • css-loader configured with esModule: false (the loader reads CSS module class names from exports.locals)

The optional getCss loader option is serialized into the generated module, so it must be a self-contained function without closed-over variables.

Breaking Changes in v6

  • Static properties of the wrapped component (e.g. fetchData) are no longer hoisted onto the component returned by withStyles. Access them via the ComposedComponent property instead.
  • prop-types validation has been removed.

Getting Started

Webpack configuration:

javascript
module.exports = {
  /* ... */
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'isomorphic-style-loader',
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1,
              esModule: false
            }
          },
          'postcss-loader'
        ]
      }
    ]
  }
  /* ... */
}

Note: Configuration is the same for both client-side and server-side bundles. For more information visit https://webpack.js.org/configuration/module/.

React component example:

css
/* App.css */
.root { padding: 10px }
.title { color: red }
javascript
/* App.js */
import React from 'react'
import withStyles from 'isomorphic-style-loader/withStyles'
import s from './App.scss'

function App(props, context) {
  return (
    

  )
}

export default withStyles(s)(App) //  {
  const css = new Set() // CSS for all rendered React components
  const insertCss = (...styles) => styles.forEach(style => css.add(style._getCss()))
  const body = ReactDOM.renderToString(
    

      
      
        

      
    `
  res.status(200).send(html)
})

server.listen(port, () => {
  console.log(`Node.js app is running at http://localhost:${port}/`)
})

It should generate an HTML output similar to this one:

xml

  
    My Application
    

    

  
  
    

    
  

Regardless of how many styles components there are in the app.js bundle, only critical CSS is going to be rendered on the server inside the `` section of HTML document. Critical CSS is what actually used on the requested web page, effectively dealing with FOUC issue and improving client-side performance. CSS of the unmounted components will be removed from the DOM.

Then on client-side use hydrate to make your markup interactive:

javascript
import React from 'react'
import ReactDOM from 'react-dom'
import StyleContext from 'isomorphic-style-loader/StyleContext'
import App from './App.js'

const insertCss = (...styles) => {
  const removeCss = styles.map(style => style._insertCss())
  return () => removeCss.forEach(dispose => dispose())
}

ReactDOM.hydrate(
  
    
  ,
  document.getElementById('root')
)

React Hooks Support:

You can also use useStyles inside your React Functional Components, instead of using withStyles. Please note that you still need to pass insertCss function to StyleContext.Provider from top of the tree.

javascript
import React from 'react'
import useStyles from 'isomorphic-style-loader/useStyles'
import s from './App.scss'

const App = (props) => {
  useStyles(s);
  return (
    

  )
};

export default App;

Related Projects

  • React Starter Kit — Isomorphic web app boilerplate (Express.js, React, Relay)
  • Node.js API Starter — Project tempalte for building GraphQL API backends

License

The MIT License © 2015-present Kriasoft (@kriasoft). All rights reserved.


Made with ♥ by Konstantin Tarkus (@koistya, blog), Vladimir Kutepov (frenzzy) and contributors

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言