Bugfix. Update generate-web-html function
This commit is contained in:
@@ -27,11 +27,10 @@ export default function watcher() {
|
||||
return;
|
||||
}
|
||||
|
||||
const target_files_match = /\.(tsx?|jsx?|css)$/;
|
||||
|
||||
if (event !== "rename") {
|
||||
if (
|
||||
filename.match(/\.(tsx?|jsx?|css)$/) &&
|
||||
global.BUNDLER_CTX
|
||||
) {
|
||||
if (filename.match(target_files_match) && global.BUNDLER_CTX) {
|
||||
if (global.RECOMPILING) return;
|
||||
global.RECOMPILING = true;
|
||||
await global.BUNDLER_CTX.rebuild();
|
||||
@@ -39,7 +38,7 @@ export default function watcher() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!filename.match(/\.(tsx?|jsx?)$/)) {
|
||||
if (!filename.match(target_files_match)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { renderToString } from "react-dom/server";
|
||||
import grabContants from "../../../utils/grab-constants";
|
||||
import EJSON from "../../../utils/ejson";
|
||||
import type { LivePageDistGenParams } from "../../../types";
|
||||
@@ -7,6 +6,8 @@ import grabWebPageHydrationScript from "./grab-web-page-hydration-script";
|
||||
import grabWebMetaHTML from "./grab-web-meta-html";
|
||||
import { log } from "../../../utils/log";
|
||||
import { AppData } from "../../../data/app-data";
|
||||
import path from "path";
|
||||
import importReactDomServer from "../../../utils/import-react-dom-server";
|
||||
|
||||
export default async function genWebHTML({
|
||||
component,
|
||||
@@ -25,6 +26,9 @@ export default async function genWebHTML({
|
||||
log.info("component", component);
|
||||
}
|
||||
|
||||
const reactDomServer = await importReactDomServer();
|
||||
const renderToString = reactDomServer.renderToString;
|
||||
|
||||
const componentHTML = renderToString(component);
|
||||
|
||||
if (debug) {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import path from "path";
|
||||
import reactDomServer from "react-dom/server";
|
||||
|
||||
export default async function importReactDomServer() {
|
||||
try {
|
||||
const reactDomServerDynamicImport = await import(
|
||||
path.join(process.cwd(), "node_modules", "react-dom", "server")
|
||||
);
|
||||
|
||||
return reactDomServerDynamicImport;
|
||||
} catch (error) {
|
||||
return reactDomServer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user