diff --git a/.changeset/dirty-tools-travel.md b/.changeset/dirty-tools-travel.md new file mode 100644 index 00000000000..91a69ee4311 --- /dev/null +++ b/.changeset/dirty-tools-travel.md @@ -0,0 +1,5 @@ +--- +'@builder.io/qwik-city': patch +--- + +fix: `zod` is now imported as `import * as z from 'zod'`, which vastly improves bundling. The Insights app client code reduced by 12kB. diff --git a/packages/docs/src/routes/docs/labs/typed-routes/index.mdx b/packages/docs/src/routes/docs/labs/typed-routes/index.mdx index 39a096b5fe6..d5655a4666f 100644 --- a/packages/docs/src/routes/docs/labs/typed-routes/index.mdx +++ b/packages/docs/src/routes/docs/labs/typed-routes/index.mdx @@ -117,7 +117,7 @@ The initialization process will create some important files for you. ### Declare Route Details ```typescript title="/src/routes/pokemon/[pokemonId]/routeInfo.ts" -import { z } from "zod"; +import * as z from "zod"; export const Route = { name: "PokemonDetail", diff --git a/packages/insights/src/routes/app/[publicApiKey]/app.form.tsx b/packages/insights/src/routes/app/[publicApiKey]/app.form.tsx index 01ab8c54b19..78f9ffce70d 100644 --- a/packages/insights/src/routes/app/[publicApiKey]/app.form.tsx +++ b/packages/insights/src/routes/app/[publicApiKey]/app.form.tsx @@ -1,4 +1,4 @@ -import { z } from 'zod'; +import * as z from 'zod'; export const ApplicationForm = z.object({ name: z.string().min(1, 'Application name is required.'), diff --git a/packages/insights/src/types/q-manifest.ts b/packages/insights/src/types/q-manifest.ts index 40f84041a56..e67c8456e66 100644 --- a/packages/insights/src/types/q-manifest.ts +++ b/packages/insights/src/types/q-manifest.ts @@ -1,4 +1,4 @@ -import { z } from 'zod'; +import * as z from 'zod'; export const QManifestSymbol = z.object({ origin: z.string(), diff --git a/packages/qwik-city/src/buildtime/vite/plugin.ts b/packages/qwik-city/src/buildtime/vite/plugin.ts index e9d0d2ae287..93e24df160a 100644 --- a/packages/qwik-city/src/buildtime/vite/plugin.ts +++ b/packages/qwik-city/src/buildtime/vite/plugin.ts @@ -70,7 +70,14 @@ function qwikCityPlugin(userOpts?: QwikCityVitePluginOptions): any { }, ssr: { external: ['node:async_hooks'], - noExternal: [QWIK_CITY, QWIK_CITY_PLAN_ID, QWIK_CITY_ENTRIES_ID, QWIK_CITY_SW_REGISTER], + noExternal: [ + QWIK_CITY, + QWIK_CITY_PLAN_ID, + QWIK_CITY_ENTRIES_ID, + QWIK_CITY_SW_REGISTER, + // We've had reports of bundling issues with zod + 'zod', + ], }, }; return updatedViteConfig; diff --git a/packages/qwik-city/src/runtime/src/server-functions.ts b/packages/qwik-city/src/runtime/src/server-functions.ts index 193362a61ab..19bda322639 100644 --- a/packages/qwik-city/src/runtime/src/server-functions.ts +++ b/packages/qwik-city/src/runtime/src/server-functions.ts @@ -14,7 +14,7 @@ import { } from '@builder.io/qwik'; import * as v from 'valibot'; -import { z } from 'zod'; +import * as z from 'zod'; import type { RequestEventLoader } from '../../middleware/request-handler/types'; import { QACTION_KEY, QDATA_KEY, QFN_KEY } from './constants'; import { RouteStateContext } from './contexts'; diff --git a/packages/qwik-city/src/runtime/src/server-functions.unit.ts b/packages/qwik-city/src/runtime/src/server-functions.unit.ts index 2e581e62ac4..1b8e3c2014b 100644 --- a/packages/qwik-city/src/runtime/src/server-functions.unit.ts +++ b/packages/qwik-city/src/runtime/src/server-functions.unit.ts @@ -1,5 +1,5 @@ import { describe, expectTypeOf, test } from 'vitest'; -import { z } from 'zod'; +import * as z from 'zod'; import { server$ } from './server-functions'; import type { RequestEventBase, ValidatorErrorType } from './types'; diff --git a/packages/qwik-labs/src/insights/index.tsx b/packages/qwik-labs/src/insights/index.tsx index 7ef4a9cf248..217ecd89723 100644 --- a/packages/qwik-labs/src/insights/index.tsx +++ b/packages/qwik-labs/src/insights/index.tsx @@ -1,5 +1,5 @@ import { component$, sync$ } from '@builder.io/qwik'; -import { z } from 'zod'; +import * as z from 'zod'; export interface InsightsPayload { /** Qwik version */ diff --git a/starters/apps/qwikcity-test/src/routes/(common)/(auth)/sign-in/index.tsx b/starters/apps/qwikcity-test/src/routes/(common)/(auth)/sign-in/index.tsx index 64563ce051c..2d70b6cb3e7 100644 --- a/starters/apps/qwikcity-test/src/routes/(common)/(auth)/sign-in/index.tsx +++ b/starters/apps/qwikcity-test/src/routes/(common)/(auth)/sign-in/index.tsx @@ -11,7 +11,7 @@ import { zod$, } from "@builder.io/qwik-city"; import { isUserAuthenticated, signIn } from "../../../../auth/auth"; -import { z } from "zod"; +import * as z from "zod"; export const onGet: RequestHandler = async ({ redirect, cookie }) => { if (await isUserAuthenticated(cookie)) {