How to use the used-styles.getUsedStyles function in used-styles

To help you get started, we’ve selected a few used-styles examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github theKashey / react-imported-component / examples / SSR / parcel-react-ssr / server / middleware.js View on Github external
export default function middleware(req, res) {
  // Generate the server-rendered HTML using the appropriate router
  const context = {};
  const markup = ReactDOM.renderToString(
    
      
    
  ) + printDrainHydrateMarks();

  // If react-router is redirecting, do it on the server side
  if (context.url) {
    return res.redirect(301, context.url);
  }

  const usedStyles = getUsedStyles(markup, projectStyles);
  console.log('used styles', usedStyles);
  // Format the HTML using the template and send the result
  const html = generateHtml('JS will start in ~2s<br>' + markup, usedStyles);
  res.send(html);
}

used-styles

Collect styles used on to create a page

MIT
Latest version published 1 month ago

Package Health Score

75 / 100
Full package analysis