Some examples of calling serverAPI in rsbuild for generating links to files from the bundler #3961
-
Hello there! I'm hoping you can help me out with some server API questions. I'm a bit lost on how to use it and need some guidance. Specifically, I need to know how to pull in links, stylesheets, JavaScript files, and other resources from the server and insert them into my HTML. I'm currently using Express for my server-side code, so I need this integration to work smoothly. Any pointers or suggestions would be greatly appreciated! Thanks in advance! I tried to use this method, but the application does not work just because everything is formed differently export function renderHtmlPage(options: {
appHtml: string
preloadedState: RootState
dehydratedState: DehydratedState
chunks: Record<'links' | 'styles' | 'scripts', string>
}): string {
const { appHtml, chunks, preloadedState, dehydratedState } = options
const helmet = Helmet.renderStatic()
const helmetScriptString = helmet.script.toString()
return `
<!DOCTYPE html>
<html ${helmet.htmlAttributes.toString()}>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="theme-color" content="#000000">
${helmet.title.toString()}
${helmet.meta.toString()}
${helmet.link.toString()}
${getGtmScript(preloadedState)}
${getIconsStyles()}
${chunks.links}
${chunks.styles}
${getIcons()}
${getOnSlowLoadAddSlowConnectionClass()}
</head>
<body class="disabled-js">
<div id="root" data-ssr="true">${appHtml}</div>
<script>
window.__PRELOADED_STATE__ = ${devalue(preloadedState)}
window.__REACT_QUERY_STATE__= ${devalue(dehydratedState)}
</script>
${chunks.scripts}
<script>document.body.classList.remove('disabled-js')</script>
</body>
</html>`
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
By default, scripts and links associated with the current page are automatically inserted into the HTML template. At this time, the compiled HTML template content can be obtained through getTransformedHtml. When you need to dynamically generate HTML on the server side, you can get manifest information using output.manifest configuration or Reference https://rsbuild.dev/guide/advanced/ssr#get-manifest |
Beta Was this translation helpful? Give feedback.
By default, scripts and links associated with the current page are automatically inserted into the HTML template. At this time, the compiled HTML template content can be obtained through getTransformedHtml.
When you need to dynamically generate HTML on the server side, you can get manifest information using output.manifest configuration or
environments.web.getStats()
.Reference https://rsbuild.dev/guide/advanced/ssr#get-manifest