Skip to content

Commit 0a1c70e

Browse files
committed
chore: move devSsrServer option to qwikRouter()
1 parent 60ffa2e commit 0a1c70e

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

packages/qwik-router/src/buildtime/vite/plugin.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ function qwikRouterPlugin(userOpts?: QwikRouterVitePluginOptions): any {
5151
let viteCommand: string;
5252
let devServer: ViteDevServer | null = null;
5353

54+
let devSsrServer = userOpts?.devSsrServer;
55+
5456
const api: QwikRouterPluginApi = {
5557
getBasePathname: () => ctx?.opts.basePathname ?? '/',
5658
getRoutes: () => {
@@ -136,6 +138,10 @@ function qwikRouterPlugin(userOpts?: QwikRouterVitePluginOptions): any {
136138
if (!qwikPlugin) {
137139
throw new Error('Missing vite-plugin-qwik');
138140
}
141+
if (typeof devSsrServer !== 'boolean') {
142+
// read the old option from qwik plugin
143+
devSsrServer = qwikPlugin.api._oldDevSsrServer();
144+
}
139145
qwikPlugin.api.registerBundleGraphAdder?.((manifest) => {
140146
return getRouteImports(ctx!.routes, manifest);
141147
});
@@ -172,10 +178,12 @@ function qwikRouterPlugin(userOpts?: QwikRouterVitePluginOptions): any {
172178
}
173179
});
174180

175-
// this callback runs after all other middlewares have been added, so we can SSR as the last middleware
176-
return () => {
177-
server.middlewares.use(makeRouterDevMiddleware(server, ctx!));
178-
};
181+
if (userOpts?.devSsrServer !== false) {
182+
// this callback runs after all other middlewares have been added, so we can SSR as the last middleware
183+
return () => {
184+
server.middlewares.use(makeRouterDevMiddleware(server, ctx!));
185+
};
186+
}
179187
},
180188

181189
transformIndexHtml() {

packages/qwik-router/src/buildtime/vite/qwik-router.buildtime.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface QwikRouterPlugin extends P<QwikRouterPluginApi> {
4444
//
4545
// @public (undocumented)
4646
export interface QwikRouterVitePluginOptions extends Omit<PluginOptions, 'basePathname'> {
47+
devSsrServer?: boolean;
4748
// Warning: (ae-forgotten-export) The symbol "ImageOptimizationOptions" needs to be exported by the entry point index.d.ts
4849
//
4950
// (undocumented)

packages/qwik-router/src/buildtime/vite/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ export interface QwikRouterVitePluginOptions extends Omit<PluginOptions, 'basePa
3434
imageOptimization?: ImageOptimizationOptions;
3535
/** Whether to use static imports for route modules (layout and index files). Defaults to `false`. */
3636
staticImportRoutes?: boolean;
37+
/**
38+
* Qwik is an SSR first framework. This means that Qwik requires either SSR or SSG. In Vite dev
39+
* mode the dev SSR server is responsible for rendering and pausing the application on the
40+
* server.
41+
*
42+
* Under normal circumstances this should be on, unless you have your own dev SSR server setup and
43+
* wish to disable this one.
44+
*
45+
* Default: true
46+
*/
47+
devSsrServer?: boolean;
3748
}
3849

3950
/** @public */

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
7676
getClientPublicOutDir: () => clientPublicOutDir,
7777
getAssetsDir: () => viteAssetsDir,
7878
registerBundleGraphAdder: (adder: BundleGraphAdder) => bundleGraphAdders.add(adder),
79+
_oldDevSsrServer: () => qwikViteOpts.devSsrServer,
7980
};
8081

8182
// We provide two plugins to Vite. The first plugin is the main plugin that handles all the
@@ -825,15 +826,7 @@ interface QwikVitePluginSSROptions extends QwikVitePluginCommonOptions {
825826
manifestOutput?: (manifest: QwikManifest) => Promise<void> | void;
826827
};
827828

828-
/**
829-
* Qwik is SSR first framework. This means that Qwik requires either SSR or SSG. In dev mode the
830-
* dev SSR server is responsible for rendering and pausing the application on the server.
831-
*
832-
* Under normal circumstances this should be on, unless you have your own SSR server which you
833-
* would like to use instead and wish to disable this one.
834-
*
835-
* Default: true
836-
*/
829+
/** @deprecated Use the `devSsrServer` option of the qwikRouter() plugin instead. */
837830
devSsrServer?: boolean;
838831

839832
/** Controls the SSR behavior. */
@@ -882,6 +875,8 @@ export interface QwikVitePluginApi {
882875
getClientPublicOutDir: () => string | null;
883876
getAssetsDir: () => string | undefined;
884877
registerBundleGraphAdder: (adder: BundleGraphAdder) => void;
878+
/** @internal */
879+
_oldDevSsrServer: () => boolean | undefined;
885880
}
886881

887882
/**

packages/qwik/src/optimizer/src/qwik.optimizer.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ export interface QwikVitePluginApi {
293293
getOptions: () => NormalizedQwikPluginOptions;
294294
// (undocumented)
295295
getRootDir: () => string | null;
296+
// @internal (undocumented)
297+
_oldDevSsrServer: () => boolean | undefined;
296298
// (undocumented)
297299
registerBundleGraphAdder: (adder: BundleGraphAdder) => void;
298300
}

0 commit comments

Comments
 (0)