perf(v2): smaller bundlesize by embedding metadata to content (#2088)

* wip embed metadata to content

* embed metadata in blog as well

* refactor

* update test

* yarn lock

* avoid overwriting file everytime we run new nodejs process

* nits
This commit is contained in:
Endi 2019-12-06 12:34:21 +07:00 committed by GitHub
parent 32c9d07b90
commit 7f8aca2ddc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 236 additions and 200 deletions

View file

@ -277,15 +277,16 @@ export default function pluginContentDocs(
const {docLayoutComponent, docItemComponent, routeBasePath} = options;
const {addRoute, createData} = actions;
const aliasedSource = (source: string) =>
`@docusaurus-plugin-content-docs/${path.relative(dataDir, source)}`;
`~docs/${path.relative(dataDir, source)}`;
const genRoutes = async (
metadataItems: Metadata[],
): Promise<RouteConfig[]> => {
const routes = await Promise.all(
metadataItems.map(async metadataItem => {
const metadataPath = await createData(
`${docuHash(metadataItem.permalink)}.json`,
await createData(
// Note that this created data path must be in sync with markdown/index.ts metadataPath
`${docuHash(metadataItem.source)}.json`,
JSON.stringify(metadataItem, null, 2),
);
return {
@ -294,7 +295,6 @@ export default function pluginContentDocs(
exact: true,
modules: {
content: metadataItem.source,
metadata: aliasedSource(metadataPath),
},
};
}),
@ -388,7 +388,7 @@ export default function pluginContentDocs(
return {
resolve: {
alias: {
'@docusaurus-plugin-content-docs': dataDir,
'~docs': dataDir,
},
},
module: {
@ -410,6 +410,7 @@ export default function pluginContentDocs(
loader: path.resolve(__dirname, './markdown/index.js'),
options: {
siteDir,
dataDir,
docsDir,
sourceToPermalink: sourceToPermalink,
versionedDir,