mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-31 18:07:00 +02:00
feat: add production entry & template
This commit is contained in:
parent
4c36e71d1f
commit
b079e48976
2 changed files with 55 additions and 0 deletions
34
lib/core/prodEntry.js
Normal file
34
lib/core/prodEntry.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
import React from 'react';
|
||||
import {BrowserRouter, StaticRouter} from 'react-router-dom';
|
||||
import ReactDOM from 'react-dom';
|
||||
import ReactDOMServer from 'react-dom/server';
|
||||
|
||||
import App from './App';
|
||||
import createHtml from './prodTemplate';
|
||||
|
||||
// Client side render (e.g: running in browser) to become single-page application (SPA)
|
||||
if (typeof document !== 'undefined') {
|
||||
ReactDOM.render(
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
</BrowserRouter>,
|
||||
document.getElementById('app')
|
||||
);
|
||||
}
|
||||
|
||||
// Renderer for static-site-generator-webpack-plugin (async rendering via callbacks)
|
||||
export default function render(locals, callback) {
|
||||
const context = {};
|
||||
const body = ReactDOMServer.renderToString(
|
||||
<StaticRouter location={locals.path} context={context}>
|
||||
<App />
|
||||
</StaticRouter>
|
||||
);
|
||||
const html = createHtml({
|
||||
title: locals.title,
|
||||
body,
|
||||
bundlejs: locals.bundlejs,
|
||||
lang: locals.lang
|
||||
});
|
||||
callback(null, html);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue