Skip to content

Commit

Permalink
perf(remix-dev/vite): extract route module exports in parallel (#8111)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Dalgleish <mark.john.dalgleish@gmail.com>
  • Loading branch information
hi-ogawa and markdalgleish committed Nov 26, 2023
1 parent 7ad2c82 commit f0f675c
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,23 @@ const writeFileSafe = async (file: string, contents: string): Promise<void> => {
await fse.writeFile(file, contents);
};

const getRouteManifestModuleExports = async (
viteChildCompiler: Vite.ViteDevServer | null,
pluginConfig: ResolvedRemixVitePluginConfig
): Promise<Record<string, string[]>> => {
let entries = await Promise.all(
Object.entries(pluginConfig.routes).map(async ([key, route]) => {
let sourceExports = await getRouteModuleExports(
viteChildCompiler,
pluginConfig,
route.file
);
return [key, sourceExports] as const;
})
);
return Object.fromEntries(entries);
};

const getRouteModuleExports = async (
viteChildCompiler: Vite.ViteDevServer | null,
pluginConfig: ResolvedRemixVitePluginConfig,
Expand Down Expand Up @@ -390,13 +407,15 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
);

let routes: Manifest["routes"] = {};

let routeManifestExports = await getRouteManifestModuleExports(
viteChildCompiler,
pluginConfig
);

for (let [key, route] of Object.entries(pluginConfig.routes)) {
let routeFilePath = path.join(pluginConfig.appDirectory, route.file);
let sourceExports = await getRouteModuleExports(
viteChildCompiler,
pluginConfig,
route.file
);
let sourceExports = routeManifestExports[key];

routes[key] = {
id: route.id,
Expand Down Expand Up @@ -434,13 +453,13 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
let pluginConfig = await resolvePluginConfig();
let routes: Manifest["routes"] = {};

for (let [key, route] of Object.entries(pluginConfig.routes)) {
let sourceExports = await getRouteModuleExports(
viteChildCompiler,
pluginConfig,
route.file
);
let routeManifestExports = await getRouteManifestModuleExports(
viteChildCompiler,
pluginConfig
);

for (let [key, route] of Object.entries(pluginConfig.routes)) {
let sourceExports = routeManifestExports[key];
routes[key] = {
id: route.id,
parentId: route.parentId,
Expand Down

0 comments on commit f0f675c

Please sign in to comment.