// noop
}
}
mdxComponents = sys.normalizePath(mdxComponents);
} else if (mdxCounter === 0 && hasMdx) {
hasMdx = false;
mdx = null;
}
}
async function config_init$() {
if (viteCommand !== "build")
logger.info("Initializing router configuration 🚦");
try {
while (config_destroy.length > 0) {
await config_destroy.pop()();
}
entry.layouts = [];
entry.pages = [];
entry.middlewares = [];
entry.api = [];
entry.resources = [];
manifest.pages = [];
manifest.middlewares = [];
config = await loadConfig({}, options);
configRoot = forRoot(config);
root = configRoot.root;
routerConfig = forChild(root, config);
entryConfig = {
layout: mergeOrApply(
mergeOrApply({ ...defaultEntryConfig.layout }, routerConfig.layout),
routerConfig.router
),
page: mergeOrApply(
mergeOrApply(
{
...defaultEntryConfig.page,
excludes: [
...defaultEntryConfig.page.excludes,
routerConfig.mdx?.components ?? "mdx-components.{jsx,tsx}",
],
},
routerConfig.page
),
routerConfig.router
),
middleware: mergeOrApply(
mergeOrApply(
{ ...defaultEntryConfig.middleware },
routerConfig.middleware
),
routerConfig.router
),
api: mergeOrApply(
mergeOrApply({ ...defaultEntryConfig.api }, routerConfig.api),
routerConfig.router
),
resource: mergeOrApply(
mergeOrApply(
{ ...defaultEntryConfig.resource },
routerConfig.resource
),
routerConfig.router
),
};
rootDir = sys.normalizePath(join(cwd, root));
if (viteCommand === "build") {
const sourceFiles = await glob(
["**/*.{jsx,tsx,js,ts,mjs,mts,md,mdx,json}", "!**/node_modules/**"],
{
cwd: join(cwd, root),
absolute: true,
// Walk into dot-prefixed directories (e.g. `.well-known/`) so
// route files under public-by-convention paths are picked up.
// fast-glob defaults to `dot: false`.
dot: true,
}
);
entry.layouts = source(
match(
sourceFiles,
entryConfig.layout.includes,
entryConfig.layout.excludes
),
rootDir,
root
);
entry.pages = source(
match(
sourceFiles,
entryConfig.page.includes,
entryConfig.page.excludes
),
rootDir,
root
);
entry.middlewares = source(
match(
sourceFiles,
entryConfig.middleware.includes,
entryConfig.middleware.excludes
),
rootDir,
root
);
entry.api = source(
match(
sourceFiles,
entryConfig.api.includes,
entryConfig.api.excludes
),
rootDir,
root
);
entry.resources = source(
match(
sourceFiles,
entryConfig.resource.includes,
entryConfig.resource.excludes
),
rootDir,
root
);
// Inject virtual routes from config
const virtualRoutes = normalizeVirtualRoutes(configRoot.routes);
if (virtualRoutes.length > 0) {
injectVirtualRoutes(virtualRoutes);
}
mdxCounter = entry.pages.filter(
(page) => page.src.endsWith(".md") || page.src.endsWith(".mdx")
).length;
await setupMdx();
createManifest();
} else {
logger.info(`Router configuration ${colors.green("successful")} ✅`);
const initialFiles = new Set(
await glob(
[
"**/*.{jsx,tsx,js,ts,mjs,mts,md,mdx,json}",
"!**/node_modules/**",
routerConfig.mdx?.components ?? "mdx-components.{jsx,tsx}",
],
{
cwd: join(cwd, root),
absolute: true,
// Match the dev `watch()` below and the build glob above:
// pick up route files under dot-prefixed directories like
// `.well-known/`. fast-glob defaults to `dot: false`.
dot: true,
}
)
);
sourceWatcher = watch(
[
"**/*.{jsx,tsx,js,ts,mjs,mts,md,mdx,json}",
"!**/node_modules/**",
routerConfig.mdx?.components ?? "mdx-components.{jsx,tsx}",
],
{
cwd: join(cwd, root),
...(typeof Bun !== "undefined" && { useFsEvents: false }),
}
);
config_destroy.push(() => {
sourceWatcher.close();
});
// Inject virtual routes from config and set up dedicated watcher
const virtualRoutes = normalizeVirtualRoutes(configRoot.routes);
if (virtualRoutes.length > 0) {
injectVirtualRoutes(virtualRoutes);
const virtualFilePaths = virtualRoutes
.filter((vr) => existsSync(vr.file))
.map((vr) => sys.normalizePath(vr.file));
if (virtualFilePaths.length > 0) {
virtualWatcher = watch(virtualFilePaths, {
ignoreInitial: true,
...(typeof Bun !== "undefined" && { useFsEvents: false }),
});
virtualWatcher.on("change", (rawSrc) => {
const src = sys.normalizePath(rawSrc);
clientPageCache.delete(src);