Skip to content

Commit d66866e

Browse files
committed
fix(vite): mark core+router as unique; better optimizeDeps discovery
1 parent 991cec0 commit d66866e

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ export interface RewriteRouteOption {
112112

113113
/** @public */
114114
export interface PluginOptions {
115-
/** Directory of the `routes`. Defaults to `src/routes`. */
115+
/** Directory of the `routes`. Defaults to `"src/routes"`. */
116116
routesDir?: string;
117-
/** Directory of the `server plugins`. Defaults to `src/server-plugins`. */
117+
/** Directory of the `server plugins`. Defaults to `routesDir`. */
118118
serverPluginsDir?: string;
119119
/**
120120
* The base pathname is used to create absolute URL paths up to the `hostname`, and must always
121-
* start and end with a `/`. Defaults to `/`.
121+
* start and end with a `/`. Defaults to `"/""`.
122122
*/
123123
basePathname?: string;
124124
/**

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ function qwikRouterPlugin(userOpts?: QwikRouterVitePluginOptions): any {
5252
let devServer: ViteDevServer | null = null;
5353

5454
let devSsrServer = userOpts?.devSsrServer;
55+
const routesDir = userOpts?.routesDir ?? 'src/routes';
56+
const serverPluginsDir = userOpts?.serverPluginsDir ?? routesDir;
5557

5658
const api: QwikRouterPluginApi = {
5759
getBasePathname: () => ctx?.opts.basePathname ?? '/',
@@ -81,6 +83,7 @@ function qwikRouterPlugin(userOpts?: QwikRouterVitePluginOptions): any {
8183
},
8284
appType: 'custom',
8385
resolve: {
86+
dedupe: [QWIK_ROUTER, '@builder.io/qwik-city'],
8487
alias: [
8588
{ find: '@builder.io/qwik-city', replacement: '@qwik.dev/router' },
8689
{ find: /^@builder\.io\/qwik-city\/(.*)/, replacement: '@qwik.dev/router/$1' },
@@ -90,6 +93,12 @@ function qwikRouterPlugin(userOpts?: QwikRouterVitePluginOptions): any {
9093
],
9194
},
9295
optimizeDeps: {
96+
// Let Vite find all app deps, these are not part of the static imports from `src/root`
97+
entries: [
98+
`${routesDir}/**/index*`,
99+
`${routesDir}/**/layout*`,
100+
`${serverPluginsDir}/plugin@*`,
101+
],
93102
exclude: [
94103
QWIK_ROUTER,
95104
QWIK_ROUTER_CONFIG_ID,

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ import {
2828
import { createRollupError, normalizeRollupOutputOptions } from './rollup';
2929
import { configurePreviewServer, getViteIndexTags } from './dev';
3030

31-
const DEDUPE = [QWIK_CORE_ID, QWIK_JSX_RUNTIME_ID, QWIK_JSX_DEV_RUNTIME_ID];
31+
const DEDUPE = [
32+
QWIK_CORE_ID,
33+
QWIK_JSX_RUNTIME_ID,
34+
QWIK_JSX_DEV_RUNTIME_ID,
35+
QWIK_CORE_INTERNAL_ID,
36+
'@builder.io/qwik',
37+
'@builder.io/qwik/jsx-runtime',
38+
'@builder.io/qwik/jsx-dev-runtime',
39+
];
3240

3341
const STYLING = ['.css', '.scss', '.sass', '.less', '.styl', '.stylus'];
3442
const FONTS = ['.woff', '.woff2', '.ttf'];

0 commit comments

Comments
 (0)