diff --git a/packages/docs/src/routes/api/qwik-optimizer/api.json b/packages/docs/src/routes/api/qwik-optimizer/api.json index 27596ca1879..d68c0cf7c99 100644 --- a/packages/docs/src/routes/api/qwik-optimizer/api.json +++ b/packages/docs/src/routes/api/qwik-optimizer/api.json @@ -498,7 +498,7 @@ } ], "kind": "Interface", - "content": "```typescript\nexport interface QwikVitePluginApi \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [getClientOutDir](#) | | () => string \\| null | |\n| [getClientPublicOutDir](#) | | () => string \\| null | |\n| [getInsightsManifest](#) | | () => Promise<[InsightManifest](#insightmanifest) \\| null> | |\n| [getManifest](#) | | () => [QwikManifest](#qwikmanifest) \\| null | |\n| [getOptimizer](#) | | () => [Optimizer](#optimizer) \\| null | |\n| [getOptions](#) | | () => NormalizedQwikPluginOptions | |\n| [getRootDir](#) | | () => string \\| null | |", + "content": "```typescript\nexport interface QwikVitePluginApi \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [getClientOutDir](#) | | () => string \\| null | |\n| [getClientPublicOutDir](#) | | () => string \\| null | |\n| [getInsightsManifest](#) | | (clientOutDir?: string \\| null) => Promise<[InsightManifest](#insightmanifest) \\| null> | |\n| [getManifest](#) | | () => [QwikManifest](#qwikmanifest) \\| null | |\n| [getOptimizer](#) | | () => [Optimizer](#optimizer) \\| null | |\n| [getOptions](#) | | () => NormalizedQwikPluginOptions | |\n| [getRootDir](#) | | () => string \\| null | |", "editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/vite.ts", "mdFile": "qwik.qwikvitepluginapi.md" }, diff --git a/packages/docs/src/routes/api/qwik-optimizer/index.md b/packages/docs/src/routes/api/qwik-optimizer/index.md index 576cf61e6c4..a25b5ddadc9 100644 --- a/packages/docs/src/routes/api/qwik-optimizer/index.md +++ b/packages/docs/src/routes/api/qwik-optimizer/index.md @@ -515,15 +515,15 @@ export interface QwikVitePlugin export interface QwikVitePluginApi ``` -| Property | Modifiers | Type | Description | -| -------------------------- | --------- | ------------------------------------------------------------------- | ----------- | -| [getClientOutDir](#) | | () => string \| null | | -| [getClientPublicOutDir](#) | | () => string \| null | | -| [getInsightsManifest](#) | | () => Promise<[InsightManifest](#insightmanifest) \| null> | | -| [getManifest](#) | | () => [QwikManifest](#qwikmanifest) \| null | | -| [getOptimizer](#) | | () => [Optimizer](#optimizer) \| null | | -| [getOptions](#) | | () => NormalizedQwikPluginOptions | | -| [getRootDir](#) | | () => string \| null | | +| Property | Modifiers | Type | Description | +| -------------------------- | --------- | ------------------------------------------------------------------------------------------------ | ----------- | +| [getClientOutDir](#) | | () => string \| null | | +| [getClientPublicOutDir](#) | | () => string \| null | | +| [getInsightsManifest](#) | | (clientOutDir?: string \| null) => Promise<[InsightManifest](#insightmanifest) \| null> | | +| [getManifest](#) | | () => [QwikManifest](#qwikmanifest) \| null | | +| [getOptimizer](#) | | () => [Optimizer](#optimizer) \| null | | +| [getOptions](#) | | () => NormalizedQwikPluginOptions | | +| [getRootDir](#) | | () => string \| null | | [Edit this section](https://github.com/BuilderIO/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/vite.ts) diff --git a/packages/qwik-city/buildtime/vite/plugin.ts b/packages/qwik-city/buildtime/vite/plugin.ts index f0e8c451ba1..5d78295c5d5 100644 --- a/packages/qwik-city/buildtime/vite/plugin.ts +++ b/packages/qwik-city/buildtime/vite/plugin.ts @@ -258,8 +258,8 @@ function qwikCityPlugin(userOpts?: QwikCityVitePluginOptions): any { if (ctx?.target === 'ssr') { // ssr build const manifest = qwikPlugin!.api.getManifest(); - const insightsManifest = await qwikPlugin!.api.getInsightsManifest(); const clientOutDir = qwikPlugin!.api.getClientOutDir(); + const insightsManifest = await qwikPlugin!.api.getInsightsManifest(clientOutDir); if (manifest && clientOutDir) { const basePathRelDir = api.getBasePathname().replace(/^\/|\/$/, ''); diff --git a/packages/qwik-labs/src-vite/insights/index.ts b/packages/qwik-labs/src-vite/insights/index.ts index 6424ef05407..ec7df840fd7 100644 --- a/packages/qwik-labs/src-vite/insights/index.ts +++ b/packages/qwik-labs/src-vite/insights/index.ts @@ -34,7 +34,7 @@ export async function qwikInsights(qwikInsightsOpts: { logWarn('fail to fetch manifest from Insights DB'); } if (!existsSync(join(process.cwd(), outDir))) { - mkdirSync(join(process.cwd(), outDir)); + mkdirSync(join(process.cwd(), outDir), { recursive: true }); } await writeFile(join(process.cwd(), outDir, 'q-insights.json'), JSON.stringify(qManifest)); } diff --git a/packages/qwik/src/optimizer/src/api.md b/packages/qwik/src/optimizer/src/api.md index 93cceaadc0f..9ffc6008c8c 100644 --- a/packages/qwik/src/optimizer/src/api.md +++ b/packages/qwik/src/optimizer/src/api.md @@ -315,7 +315,7 @@ export interface QwikVitePluginApi { // (undocumented) getClientPublicOutDir: () => string | null; // (undocumented) - getInsightsManifest: () => Promise; + getInsightsManifest: (clientOutDir?: string | null) => Promise; // (undocumented) getManifest: () => QwikManifest | null; // (undocumented) diff --git a/packages/qwik/src/optimizer/src/plugins/vite.ts b/packages/qwik/src/optimizer/src/plugins/vite.ts index 2010b9d165b..2c7262f4cca 100644 --- a/packages/qwik/src/optimizer/src/plugins/vite.ts +++ b/packages/qwik/src/optimizer/src/plugins/vite.ts @@ -56,10 +56,10 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any { const injections: GlobalInjections[] = []; const qwikPlugin = createPlugin(qwikViteOpts.optimizerOptions); - async function loadQwikInsights(): Promise { + async function loadQwikInsights(clientOutDir?: string | null): Promise { const sys = qwikPlugin.getSys(); const fs: typeof import('fs') = await sys.dynamicImport('node:fs'); - const path = sys.path.join(process.cwd(), 'dist', 'q-insights.json'); + const path = sys.path.join(process.cwd(), clientOutDir ?? 'dist', 'q-insights.json'); if (fs.existsSync(path)) { return JSON.parse(await fs.promises.readFile(path, 'utf-8')) as InsightManifest; } @@ -70,7 +70,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any { getOptimizer: () => qwikPlugin.getOptimizer(), getOptions: () => qwikPlugin.getOptions(), getManifest: () => manifestInput, - getInsightsManifest: () => loadQwikInsights(), + getInsightsManifest: (clientOutDir?: string | null) => loadQwikInsights(clientOutDir), getRootDir: () => qwikPlugin.getOptions().rootDir, getClientOutDir: () => clientOutDir, getClientPublicOutDir: () => clientPublicOutDir, @@ -118,7 +118,9 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any { if (sys.env === 'node' && !qwikViteOpts.entryStrategy) { try { - const entryStrategy = await loadQwikInsights(); + const entryStrategy = await loadQwikInsights( + !qwikViteOpts.csr ? qwikViteOpts.client?.outDir : undefined + ); if (entryStrategy) { qwikViteOpts.entryStrategy = entryStrategy; } @@ -871,7 +873,7 @@ export interface QwikVitePluginApi { getOptimizer: () => Optimizer | null; getOptions: () => NormalizedQwikPluginOptions; getManifest: () => QwikManifest | null; - getInsightsManifest: () => Promise; + getInsightsManifest: (clientOutDir?: string | null) => Promise; getRootDir: () => string | null; getClientOutDir: () => string | null; getClientPublicOutDir: () => string | null;