Fix astro sync config merge (#6392)
* Fix astro sync config merge * Fix getViteConfig type
This commit is contained in:
parent
c1ca84a8c1
commit
ee8b2a0672
3 changed files with 27 additions and 26 deletions
5
.changeset/cold-mirrors-joke.md
Normal file
5
.changeset/cold-mirrors-joke.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Run astro sync in build mode
|
|
@ -30,7 +30,7 @@ interface CreateViteOptions {
|
||||||
settings: AstroSettings;
|
settings: AstroSettings;
|
||||||
logging: LogOptions;
|
logging: LogOptions;
|
||||||
mode: 'dev' | 'build' | string;
|
mode: 'dev' | 'build' | string;
|
||||||
// will be undefined when using `sync`
|
// will be undefined when using `getViteConfig`
|
||||||
command?: 'dev' | 'build';
|
command?: 'dev' | 'build';
|
||||||
fs?: typeof nodeFs;
|
fs?: typeof nodeFs;
|
||||||
}
|
}
|
||||||
|
@ -180,32 +180,28 @@ export async function createVite(
|
||||||
// We also need to filter out the plugins that are not meant to be applied to the current command:
|
// We also need to filter out the plugins that are not meant to be applied to the current command:
|
||||||
// - If the command is `build`, we filter out the plugins that are meant to be applied for `serve`.
|
// - If the command is `build`, we filter out the plugins that are meant to be applied for `serve`.
|
||||||
// - If the command is `dev`, we filter out the plugins that are meant to be applied for `build`.
|
// - If the command is `dev`, we filter out the plugins that are meant to be applied for `build`.
|
||||||
if (command) {
|
if (command && settings.config.vite?.plugins) {
|
||||||
let plugins = settings.config.vite?.plugins;
|
let { plugins, ...rest } = settings.config.vite;
|
||||||
if (plugins) {
|
const applyToFilter = command === 'build' ? 'serve' : 'build';
|
||||||
const { plugins: _, ...rest } = settings.config.vite;
|
const applyArgs = [
|
||||||
const applyToFilter = command === 'build' ? 'serve' : 'build';
|
{ ...settings.config.vite, mode },
|
||||||
const applyArgs = [
|
{ command, mode },
|
||||||
{ ...settings.config.vite, mode },
|
];
|
||||||
{ command, mode },
|
// @ts-expect-error ignore TS2589: Type instantiation is excessively deep and possibly infinite.
|
||||||
];
|
plugins = plugins.flat(Infinity).filter((p) => {
|
||||||
// @ts-expect-error ignore TS2589: Type instantiation is excessively deep and possibly infinite.
|
if (!p || p?.apply === applyToFilter) {
|
||||||
plugins = plugins.flat(Infinity).filter((p) => {
|
return false;
|
||||||
if (!p || p?.apply === applyToFilter) {
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof p.apply === 'function') {
|
if (typeof p.apply === 'function') {
|
||||||
return p.apply(applyArgs[0], applyArgs[1]);
|
return p.apply(applyArgs[0], applyArgs[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
result = vite.mergeConfig(result, { ...rest, plugins });
|
||||||
result = vite.mergeConfig(result, { ...rest, plugins });
|
} else {
|
||||||
} else {
|
result = vite.mergeConfig(result, settings.config.vite || {});
|
||||||
result = vite.mergeConfig(result, settings.config.vite || {});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
result = vite.mergeConfig(result, commandConfig);
|
result = vite.mergeConfig(result, commandConfig);
|
||||||
if (result.plugins) {
|
if (result.plugins) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ export async function sync(
|
||||||
optimizeDeps: { entries: [] },
|
optimizeDeps: { entries: [] },
|
||||||
logLevel: 'silent',
|
logLevel: 'silent',
|
||||||
},
|
},
|
||||||
{ settings, logging, mode: 'build', fs }
|
{ settings, logging, mode: 'build', command: 'build', fs }
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue