Skip to content

Commit

Permalink
fix: fix virtual module syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Nov 10, 2024
1 parent 6966b5a commit f2ed3c0
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/virtual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ export function createVirtualModuleID(name: string) {
export async function createVirtualGlob(
target: string,
isSync: boolean,
excludes: string[]
excludes: string[],
) {
const excludeGlobs = excludes.map(exclude => `"!${target}/${exclude}"`).join(",") 
const g = excludeGlobs === '' ? `"${target}/**/*.vue"` `"${target}/**/*.vue",` + excludeGlobs
const excludeGlobs = excludes.map((exclude) => `"!${target}/${exclude}"`)
.join(",");
const g = excludeGlobs === ""
? `"${target}/**/*.vue"`
: `"${target}/**/*.vue",` + excludeGlobs;
if (await isVite2()) {
return isSync ? `import.meta.globEager([${g}])` : `import.meta.glob([${g}])`;
return isSync
? `import.meta.globEager([${g}])`
: `import.meta.glob([${g}])`;
}
return `import.meta.glob([${g}], { eager: ${isSync} })`;
}
Expand All @@ -33,8 +38,13 @@ interface VirtualModuleCodeOptions {
export async function createVirtualModuleCode(
options: VirtualModuleCodeOptions,
) {
const { target, defaultLayout, importMode, skipTopLevelRouteLayout, excludes } =
options;
const {
target,
defaultLayout,
importMode,
skipTopLevelRouteLayout,
excludes,
} = options;

const normalizedTarget = normalizePath(target);

Expand Down Expand Up @@ -63,7 +73,7 @@ export function setupLayouts(routes) {
const modules = ${await createVirtualGlob(
normalizedTarget,
isSync,
excludes
excludes,
)}
Object.entries(modules).forEach(([name, module]) => {
Expand Down

0 comments on commit f2ed3c0

Please sign in to comment.