feat: enable custom theme with eject

This commit is contained in:
endiliey 2018-08-30 01:03:38 +08:00
parent 8c6bc6dd38
commit 2b5ee3e869
6 changed files with 40 additions and 7 deletions

View file

@ -20,7 +20,6 @@ module.exports = function loadConfig(siteDir, deleteCache = true) {
];
const optionalFields = [
'customDocsPath',
'themePath',
'highlight',
'markdownPlugins'
];

View file

@ -34,11 +34,19 @@ module.exports = async function load(siteDir) {
const outDir = path.resolve(siteDir, 'build');
// resolve the theme
const themePath =
siteConfig.themePath &&
fs.existsSync(path.resolve(siteDir, siteConfig.themePath))
? siteConfig.themePath
: path.resolve(__dirname, '../theme');
const customThemePath = path.resolve(siteDir, 'theme');
const themePath = fs.existsSync(customThemePath)
? customThemePath
: path.resolve(__dirname, '../theme');
const themeComponents = ['Docs', 'Loading', 'NotFound'];
themeComponents.forEach(component => {
if (!require.resolve(path.join(themePath, component))) {
throw new Error(
`Failed to load ${themePath}/${component}. It does not exist.`
);
}
});
const baseUrl = siteConfig.baseUrl || '/';