简体   繁体   中英

customize-cra Minify and Embbeed CSS into HTML

I am working on a React project. I want my CSS to be embedded into HTML itself without having a network call for CSS.

CSS

body{
   background-color: #000000;
}

into one file like

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <title>React App</title>
    <style>
    body{
      background-color: #000000;
    }
    </style>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
  </body>
</html>

I have no knowledge of webpack I have setup customize-cra and have config-override.js file.

module.exports = function override(config, env) {
  // do stuff with the webpack config...
  return config;
};

May be this is what you need "react-style-tag"

From your post I think you want to have your styles inside the of your index.html file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM