diff --git a/src/loaders/markdown/index.ts b/src/loaders/markdown/index.ts index ee1b7fd42..349810dc5 100644 --- a/src/loaders/markdown/index.ts +++ b/src/loaders/markdown/index.ts @@ -144,15 +144,18 @@ function emitDemo( const { demos } = ret.meta; const shareDepsMap: Record = {}; const demoDepsMap: Record> = {}; + const relativeDepsMap: Record> = {}; demos?.forEach((demo) => { if ('resolveMap' in demo && 'asset' in demo) { const entryFileName = Object.keys(demo.asset.dependencies)[0]; demoDepsMap[demo.id] ??= {}; + relativeDepsMap[demo.id] ??= {}; Object.keys(demo.resolveMap).forEach((key, index) => { const specifier = `${demo.id.replace(/[^\w\d]/g, '_')}_deps_${index}`; if (key !== entryFileName) { - const normalizedKey = isRelativePath(key) + const isRelative = isRelativePath(key); + const normalizedKey = isRelative ? winPath(demo.resolveMap[key]) : key; @@ -162,6 +165,12 @@ function emitDemo( } else { demoDepsMap[demo.id][normalizedKey] = shareDepsMap[normalizedKey]; } + + if (isRelative) { + relativeDepsMap[demo.id][key] = `{{{${ + shareDepsMap[normalizedKey] || specifier + }}}}`; + } } }); } @@ -244,7 +253,7 @@ export const demos = { ...acc, ...{ [key]: `{{{${specifier}}}}` }, }), - {}, + relativeDepsMap[this.id], ); return JSON.stringify(context, null, 2).replace(/"{{{|}}}"/g, ''); },