作为一个没有编译器背景的人,他们努力使Linaria在后端工作。
我的问题是我目前正在后端上滚动Typescript / Express / NodeJS,并且我想在服务器端渲染包含“ Linaria”的React-App,需要使用babel对其进行编译。
我如何将以下代码转换为通过babel转译器以编程方式传递App并以某种方式对其进行SSR?仍然不知道那是怎么回事。
import { Request, Response } from "express";
import * as React from "react";
import ReactDOMServer from "react-dom/server";
import { ServerStyleSheet, StyleSheetManager } from "styled-components";
import { StaticRouter } from "react-router";
import { memoize } from "../util/memoize/memoize";
import { collect } from "linaria/server";
import { App } from "../../frontend/src/App";
const serverRender = memoize((url: string) => {
const context = {};
try {
const html = ReactDOMServer.renderToStaticMarkup(
<StaticRouter location={url} context={context}>
<App />
</StaticRouter>
); // Fails on <App/> Because styled hasn't been converted using babel.
console.log(html);
} catch (error) {
// handle error
console.error(error);
}
});