Skip to content

Commit

Permalink
fix(vite): update other executors to use resolveConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Oct 15, 2024
1 parent 16bb1e3 commit 0a744f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
12 changes: 7 additions & 5 deletions packages/vite/src/executors/dev-server/dev-server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function* viteDevServerExecutor(
): AsyncGenerator<{ success: boolean; baseUrl: string }> {
process.env.VITE_CJS_IGNORE_WARNING = 'true';
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
const { mergeConfig, createServer, loadConfigFromFile } =
const { mergeConfig, createServer, resolveConfig } =
await loadViteDynamicImport();

const projectRoot =
Expand Down Expand Up @@ -56,20 +56,21 @@ export async function* viteDevServerExecutor(
buildOptions,
otherOptionsFromBuild
);
const resolved = await loadConfigFromFile(
const resolved = await resolveConfig(
{
configFile: viteConfigPath,
mode: otherOptions?.mode ?? buildTargetOptions?.['mode'] ?? 'development',
command: 'serve',
},
viteConfigPath
'serve',
otherOptions?.mode ?? buildTargetOptions?.['mode'] ?? 'development'
);

// vite InlineConfig
const serverConfig = mergeConfig(
{
// This should not be needed as it's going to be set in vite.config.ts
// but leaving it here in case someone did not migrate correctly
root: resolved.config.root ?? root,
root: resolved.root ?? root,
configFile: viteConfigPath,
},
{
Expand Down Expand Up @@ -107,6 +108,7 @@ export async function* viteDevServerExecutor(
process.once('exit', () => resolve());
});
}

// vite ViteDevServer
async function runViteDevServer(server: Record<string, any>): Promise<void> {
await server.listen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export async function* vitePreviewServerExecutor(
) {
process.env.VITE_CJS_IGNORE_WARNING = 'true';
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
const { mergeConfig, preview, loadConfigFromFile } =
await loadViteDynamicImport();
const { mergeConfig, preview, resolveConfig } = await loadViteDynamicImport();
const projectRoot =
context.projectsConfigurations.projects[context.projectName].root;
const target = parseTargetString(options.buildTarget, context);
Expand Down Expand Up @@ -61,12 +60,13 @@ export async function* vitePreviewServerExecutor(
configuration,
otherOptionsFromBuild
);
const resolved = await loadConfigFromFile(
const resolved = await resolveConfig(
{
configFile: viteConfigPath,
mode: otherOptions?.mode ?? otherOptionsFromBuild?.mode ?? 'production',
command: 'build',
},
viteConfigPath
'build',
otherOptions?.mode ?? otherOptionsFromBuild?.mode ?? 'production'
);

const outDir =
Expand All @@ -75,7 +75,7 @@ export async function* vitePreviewServerExecutor(
offsetFromRoot(projectRoot),
buildTargetOptions.outputPath
) ??
resolved?.config?.build?.outDir;
resolved?.build?.outDir;

if (!outDir) {
throw new Error(
Expand Down Expand Up @@ -108,7 +108,7 @@ export async function* vitePreviewServerExecutor(
{
// This should not be needed as it's going to be set in vite.config.ts
// but leaving it here in case someone did not migrate correctly
root: resolved.config.root ?? root,
root: resolved.root ?? root,
configFile: viteConfigPath,
},
{
Expand Down

0 comments on commit 0a744f3

Please sign in to comment.