mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-07 13:22:26 +02:00
refactor(v2): minor code refactoring on component creator (#2080)
This commit is contained in:
parent
af059e61de
commit
b26948d485
1 changed files with 11 additions and 27 deletions
|
@ -10,6 +10,7 @@ import Loadable from 'react-loadable';
|
||||||
import Loading from '@theme/Loading';
|
import Loading from '@theme/Loading';
|
||||||
import routesChunkNames from '@generated/routesChunkNames';
|
import routesChunkNames from '@generated/routesChunkNames';
|
||||||
import registry from '@generated/registry';
|
import registry from '@generated/registry';
|
||||||
|
import flat from '../flat';
|
||||||
|
|
||||||
function ComponentCreator(path) {
|
function ComponentCreator(path) {
|
||||||
// 404 page
|
// 404 page
|
||||||
|
@ -36,34 +37,17 @@ function ComponentCreator(path) {
|
||||||
- optsModules: ['./Pages.js', './doc1.md']
|
- optsModules: ['./Pages.js', './doc1.md']
|
||||||
- optsWebpack: [require.resolveWeak('./Pages.js'), require.resolveWeak('./doc1.md')]
|
- optsWebpack: [require.resolveWeak('./Pages.js'), require.resolveWeak('./doc1.md')]
|
||||||
*/
|
*/
|
||||||
function traverseChunk(target, keys) {
|
const flatChunkNames = flat(chunkNames);
|
||||||
if (Array.isArray(target)) {
|
Object.keys(flatChunkNames).forEach(key => {
|
||||||
target.forEach((value, index) => {
|
const chunkRegistry = registry[flatChunkNames[key]];
|
||||||
traverseChunk(value, [...keys, index]);
|
if (chunkRegistry) {
|
||||||
});
|
/* eslint-disable prefer-destructuring */
|
||||||
return;
|
optsLoader[key] = chunkRegistry[0];
|
||||||
|
optsModules.push(chunkRegistry[1]);
|
||||||
|
optsWebpack.push(chunkRegistry[2]);
|
||||||
|
/* eslint-enable prefer-destructuring */
|
||||||
}
|
}
|
||||||
|
});
|
||||||
if (target == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof target === 'object') {
|
|
||||||
Object.keys(target).forEach(key => {
|
|
||||||
traverseChunk(target[key], [...keys, key]);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const chunkRegistry = registry[target] || {};
|
|
||||||
/* eslint-disable prefer-destructuring */
|
|
||||||
optsLoader[keys.join('.')] = chunkRegistry[0];
|
|
||||||
optsModules.push(chunkRegistry[1]);
|
|
||||||
optsWebpack.push(chunkRegistry[2]);
|
|
||||||
/* eslint-enable prefer-destructuring */
|
|
||||||
}
|
|
||||||
|
|
||||||
traverseChunk(chunkNames, []);
|
|
||||||
|
|
||||||
return Loadable.Map({
|
return Loadable.Map({
|
||||||
loading: Loading,
|
loading: Loading,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue