Skip to content

Commit ce12588

Browse files
authored
Merge pull request #8127 from gnemanja/v2-out-dir-fix
fix(v2): qwikVite client outDir fix
2 parents cb19ff7 + 8c7943d commit ce12588

File tree

4 files changed

+52
-52
lines changed

4 files changed

+52
-52
lines changed

.changeset/angry-jokes-brush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@qwik.dev/core': patch
3+
---
4+
5+
FIX: Qwik vite plugin respects outDir change

packages/docs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@mui/x-data-grid": "8.11.3",
1818
"@qwik-ui/headless": "0.6.7",
1919
"@qwik.dev/core": "workspace:*",
20+
"@qwik.dev/devtools": "0.2.1",
2021
"@qwik.dev/partytown": "0.11.2",
2122
"@qwik.dev/react": "workspace:*",
2223
"@qwik.dev/router": "workspace:*",
@@ -57,8 +58,7 @@
5758
"valibot": "0.33.3",
5859
"vite": "7.1.11",
5960
"vite-tsconfig-paths": "5.1.4",
60-
"wrangler": "3.65.1",
61-
"@qwik.dev/devtools": "0.2.1"
61+
"wrangler": "3.65.1"
6262
},
6363
"engines": {
6464
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",

packages/qwik/src/optimizer/src/plugins/vite.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
6868
let rootDir: string | null = null;
6969

7070
let ssrOutDir: string | null = null;
71+
// Cache the user-specified clientOutDir to use across multiple normalizeOptions calls
72+
const userClientOutDir = qwikViteOpts.client?.outDir;
73+
// Cache the resolved plugin options from config() to reuse in configResolved()
74+
let cachedPluginOpts: QwikPluginOptions | null = null;
7175
const fileFilter: QwikVitePluginOptions['fileFilter'] = qwikViteOpts.fileFilter
7276
? (id, type) => TRANSFORM_REGEX.test(id) || qwikViteOpts.fileFilter!(id, type)
7377
: () => true;
@@ -168,9 +172,10 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
168172
outDir: viteConfig.build?.outDir,
169173
ssrOutDir: qwikViteOpts.ssr?.outDir || viteConfig.build?.outDir,
170174
clientOutDir:
171-
qwikViteOpts.client?.outDir ||
175+
userClientOutDir ||
172176
// When ssr is true, this is probably an adapter build and not where the client build is
173-
(viteConfig.build?.ssr ? undefined : viteConfig.build?.outDir),
177+
// However, if client.outDir was explicitly set, always use it
178+
(viteConfig.build?.ssr && !userClientOutDir ? undefined : viteConfig.build?.outDir),
174179
assetsDir: useAssetsDir ? viteAssetsDir : undefined,
175180
devTools: qwikViteOpts.devTools,
176181
sourcemap: !!viteConfig.build?.sourcemap,
@@ -185,6 +190,9 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
185190
const opts = await qwikPlugin.normalizeOptions(pluginOpts);
186191
input ||= opts.input;
187192

193+
// Cache pluginOpts for use in configResolved()
194+
cachedPluginOpts = pluginOpts;
195+
188196
manifestInput = opts.manifestInput;
189197
srcDir = opts.srcDir;
190198
rootDir = opts.rootDir;
@@ -358,7 +366,12 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
358366
qwikPlugin.setSourceMapSupport(true);
359367
}
360368
// Ensure that the final settings are applied
361-
qwikPlugin.normalizeOptions(qwikViteOpts);
369+
// Use cachedPluginOpts if available to preserve clientOutDir
370+
if (cachedPluginOpts) {
371+
qwikPlugin.normalizeOptions(cachedPluginOpts);
372+
} else {
373+
qwikPlugin.normalizeOptions(qwikViteOpts);
374+
}
362375
},
363376

364377
async buildStart() {

0 commit comments

Comments
 (0)