繁体   English   中英

custom-cra 将 CSS 压缩并嵌入到 HTML 中

[英]customize-cra Minify and Embbeed CSS into 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>

我不了解 webpack 我已经设置了 custom customize-cra并且有config-override.js文件。

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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