首页 > 解决方案 > custom-cra 缩小 CSS 并将其嵌入 HTML

问题描述

我正在做一个 React 项目。我希望我的 CSS 嵌入到 HTML 本身中,而不需要对 CSS 进行网络调用。

CSS

body{
   background-color: #000000;
}

到一个文件中

<!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>

我不知道我已经设置customize-cra并有config-override.js文件的 webpack。

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

标签: reactjswebpackcreate-react-app

解决方案


可能这就是你需要的“react-style-tag”

从您的帖子中,我认为您希望将样式包含在 index.html 文件中


推荐阅读