diff --git a/.changeset/config.json b/.changeset/config.json index 8c380c2..af9ea7c 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -15,5 +15,5 @@ "___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": { "updateInternalDependents": "always" }, - "ignore": ["@examples/hackernews", "@examples/normal"] + "ignore": ["@examples/hackernews", "@examples/normal", "@examples/with-antd4"] } diff --git a/.changeset/witty-balloons-jump.md b/.changeset/witty-balloons-jump.md new file mode 100644 index 0000000..0d63ebd --- /dev/null +++ b/.changeset/witty-balloons-jump.md @@ -0,0 +1,5 @@ +--- +'@umijs/tnf': patch +--- + +feat: add router config diff --git a/README.md b/README.md index f4f4318..acc78d2 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Config is loaded from `.tnfrc.ts` by default. - `devServer: { port?: number; host?: string; https?: { hosts?: string[] }; ip?: string }`: The development server configuration. - `externals: Record`: An object that maps package names to their corresponding paths. - `less: { modifyVars?: Record; globalVars?: Record; math?: 'always' | 'strict' | 'parens-division' | 'parens' | 'strict-legacy' | number; sourceMap?: any; plugins?: (string | [string, Record])[];}`: The configuration passed to lessLoader. +- `router: { defaultPreload?: 'intent' | 'render' | 'viewport'; defaultPreloadDelay?: number }`: The router configuration. ## LICENSE diff --git a/examples/normal/.tnfrc.ts b/examples/normal/.tnfrc.ts index ff8b4c5..22fd135 100644 --- a/examples/normal/.tnfrc.ts +++ b/examples/normal/.tnfrc.ts @@ -1 +1,5 @@ -export default {}; +export default { + router: { + defaultPreload: 'intent', + }, +}; diff --git a/examples/normal/src/pages/__root.tsx b/examples/normal/src/pages/__root.tsx index fac4c83..3b88c7a 100644 --- a/examples/normal/src/pages/__root.tsx +++ b/examples/normal/src/pages/__root.tsx @@ -10,9 +10,7 @@ export const Route = createRootRoute({ Home
  • - - Foo - + Foo
  • diff --git a/src/build.ts b/src/build.ts index ce31abd..e08c6dd 100644 --- a/src/build.ts +++ b/src/build.ts @@ -22,6 +22,7 @@ export async function build({ await prepare({ cwd, tmpPath, + config, }); }; diff --git a/src/config.ts b/src/config.ts index 3165069..75c28ce 100644 --- a/src/config.ts +++ b/src/config.ts @@ -28,6 +28,12 @@ const ConfigSchema = z.object({ plugins: z.array(z.any()).optional(), }) .optional(), + router: z + .object({ + defaultPreload: z.enum(['intent', 'render', 'viewport']).optional(), + defaultPreloadDelay: z.number().optional(), + }) + .optional(), }); export type Config = z.infer; diff --git a/src/prepare.ts b/src/prepare.ts index 04058e6..87b9bf0 100644 --- a/src/prepare.ts +++ b/src/prepare.ts @@ -2,16 +2,18 @@ import { generator } from '@tanstack/router-generator'; import type { Config } from '@tanstack/router-generator'; import fs from 'fs'; import path from 'pathe'; +import type { Config as TnfConfig } from './config'; interface BaseOptions { cwd: string; tmpPath: string; + config?: TnfConfig; } interface PrepareOptions extends BaseOptions {} export async function prepare(opts: PrepareOptions) { - const { cwd, tmpPath } = opts; + const { cwd, tmpPath, config } = opts; fs.rmSync(tmpPath, { recursive: true, force: true }); fs.mkdirSync(tmpPath, { recursive: true }); @@ -55,6 +57,8 @@ import { import { routeTree } from './routeTree.gen'; const router = createRouter({ routeTree, + defaultPreload: ${config?.router?.defaultPreload ? `'${config.router.defaultPreload}'` : 'false'}, + defaultPreloadDelay: ${config?.router?.defaultPreloadDelay || 50}, }); declare module '@tanstack/react-router' { interface Register {