From 12d4473d7c11ed844c1b74585cefef4fe780135f Mon Sep 17 00:00:00 2001 From: pikax Date: Tue, 5 May 2020 20:12:02 +0100 Subject: [PATCH] improvements --- src/build/bundle.ts | 11 +++++++++++ src/utils/pathResolver.ts | 7 ++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/build/bundle.ts b/src/build/bundle.ts index bb52e919..e319a7d1 100644 --- a/src/build/bundle.ts +++ b/src/build/bundle.ts @@ -33,6 +33,17 @@ export async function bundle( if (id === '/@siteData') { return `export default ${JSON.stringify(JSON.stringify(config.site))}` } + + if (id === '/@components') { + const componentsFiles = ( + await fs.readdir(config.componentDir) + ).map((x) => [ + path.basename(x, path.extname(x)), + path.extname(x).slice(1) + ]) + return `export default ${JSON.stringify(componentsFiles)}` + } + // compile md into vue src for .md.vue virtual files if (id.endsWith('.md')) { const filePath = id.replace(/\.vue$/, '') diff --git a/src/utils/pathResolver.ts b/src/utils/pathResolver.ts index 588b34e6..c8767998 100644 --- a/src/utils/pathResolver.ts +++ b/src/utils/pathResolver.ts @@ -24,11 +24,8 @@ export function createResolver( if (publicPath.startsWith('/@theme')) { return path.join(themeDir, publicPath.replace(/^\/@theme\/?/, '')) } - if (publicPath.startsWith('/@components/index')) { - return path.join( - componentDir, - publicPath.replace(/^\/@components\/?/, '') - ) + if (publicPath === '/@components') { + return publicPath } if (publicPath.startsWith('/@components')) { return path.join(