简体   繁体   English

react-snap 未在页面上呈现 html

[英]react-snap is not rendering html on the page

I am trying to render html on the page as source code by using react-snap plugin, with the following configuration in package.json我正在尝试使用react-snap插件在页面上呈现 html 作为源代码,在package.json有以下配置

package.json包.json

{
..//
"scripts": {
    "test": "jest",
    "coverage": "jest --coverage",
    "build:prod": "rm -rf dist && webpack --mode production --config webpack.prod.js",
    "start:dev": "rm -rf dist && webpack-dev-server --mode development --config webpack.dev.js",
    "postbuild": "react-snap"
  },
"reactSnap": {
    "source": "dist",
    "inlineCss": true,
    "removeBlobs": true,
    "removeScriptTags": true,
    "removeStyleTags": true,
    "minifyHtml": {
      "collapseWhitespace": false,
      "removeComments": false
    }
  },
..//
}

index.js索引.js

import { hydrate, render } from "react-dom";
const rootElement = document.getElementById("root");
if (rootElement.hasChildNodes()) {
    hydrate(<App />, rootElement);
} else {
    render(<App />, rootElement);
}

but Its not working at all, please help但它根本不起作用,请帮忙

I've had problem when enabling the inlineCss option too.我在启用 inlineCss 选项时也遇到了问题。 Turn it to false and try again.将其设置为 false 并重试。

"inlineCss": false,

It works with the default options too so you could completely remove the react-snap options in your package.json file.它也适用于默认选项,因此您可以完全删除 package.json 文件中的 react-snap 选项。

But beware with react-snap I'm having other problems related to page refresh and react-router-dom.但是要注意 react-snap 我还有其他与页面刷新和 react-router-dom 相关的问题。 I'm not going to expand on this here but just know that react-snap is not perfect.我不打算在这里扩展这个,但只知道 react-snap 并不完美。

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

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