mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-10 23:02:56 +02:00
feat: code split & use react helmet
This commit is contained in:
parent
bf1e30dc52
commit
406106b67e
19 changed files with 241 additions and 146 deletions
|
@ -1,40 +1,32 @@
|
|||
const {fileToComponentName} = require('./utils');
|
||||
|
||||
async function genRoutesConfig({docsData = [], pagesData = []}) {
|
||||
function genDocsRoute({path: docsPath, source}) {
|
||||
const componentName = fileToComponentName(source);
|
||||
return `
|
||||
{
|
||||
path: ${JSON.stringify(docsPath)},
|
||||
exact: true,
|
||||
component: (props) => (
|
||||
<Docs {...props}>
|
||||
<${componentName} />
|
||||
</Docs>
|
||||
)
|
||||
component: Loadable({
|
||||
loader: () => import('@docs/${source}'),
|
||||
loading: Loading,
|
||||
render(loaded, props) {
|
||||
let Content = loaded.default;
|
||||
return <Docs {...props}><Content /></Docs>;
|
||||
}
|
||||
})
|
||||
}`;
|
||||
}
|
||||
|
||||
function genDocsImport({source}) {
|
||||
const componentName = fileToComponentName(source);
|
||||
return `import ${componentName} from '@docs/${source}';`;
|
||||
}
|
||||
|
||||
function genPagesRoute({path: pagesPath, source}) {
|
||||
const componentName = fileToComponentName(source);
|
||||
return `
|
||||
{
|
||||
path: ${JSON.stringify(pagesPath)},
|
||||
exact: true,
|
||||
component: ${componentName}
|
||||
component: Loadable({
|
||||
loader: () => import('@pages/${source}'),
|
||||
loading: Loading
|
||||
})
|
||||
}`;
|
||||
}
|
||||
|
||||
function genPagesImport({source}) {
|
||||
const componentName = fileToComponentName(source);
|
||||
return `import ${componentName} from '@pages/${source}';`;
|
||||
}
|
||||
|
||||
const notFoundRoute = `,
|
||||
{
|
||||
path: '*',
|
||||
|
@ -43,10 +35,10 @@ async function genRoutesConfig({docsData = [], pagesData = []}) {
|
|||
|
||||
return (
|
||||
`import React from 'react';\n` +
|
||||
`import Loading from '@theme/Loading';\n` +
|
||||
`import Loadable from 'react-loadable';\n` +
|
||||
`import Docs from '@theme/Docs';\n` +
|
||||
`import NotFound from '@theme/NotFound';\n` +
|
||||
`${pagesData.map(genPagesImport).join('\n')}\n` +
|
||||
`${docsData.map(genDocsImport).join('\n')}\n` +
|
||||
`const routes = [${docsData.map(genDocsRoute).join(',')},${pagesData
|
||||
.map(genPagesRoute)
|
||||
.join(',')}${notFoundRoute}\n];\n` +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue