diff --git a/packages/vike-react/src/+config.ts b/packages/vike-react/src/+config.ts index e6f35e5b..ddebd9d9 100644 --- a/packages/vike-react/src/+config.ts +++ b/packages/vike-react/src/+config.ts @@ -1,11 +1,10 @@ +export { config } + import type { Config } from 'vike/types' -import { isNotFalse } from './utils/isNotFalse.js' import { ssrEffect } from './renderer/ssrEffect.js' +import { isNotFalse } from './utils/isNotFalse.js' -// This is required to make TypeScript load the global interfaces such as Vike.PageContext so that they're always loaded: we can assume that the user always imports this file over `import vikeReact from 'vike-react/config'` -import './types/index.js' - -export default { +const config = { name: 'vike-react', require: { vike: '>=0.4.182' @@ -97,3 +96,7 @@ export default { } } } satisfies Config + +// This is required to make TypeScript load the global interfaces Vike.Config and Vike.PageContext so that they're always loaded: we can assume that the user always imports this file over `import vikeReact from 'vike-react/config'` +import './types/Config.js' +import './types/PageContext.js' diff --git a/packages/vike-react/src/index.ts b/packages/vike-react/src/index.ts index 88094338..42248e82 100644 --- a/packages/vike-react/src/index.ts +++ b/packages/vike-react/src/index.ts @@ -2,4 +2,4 @@ console.warn( "[vike-react][warning][deprecation] Replace `import vikeReact from 'vike-react'` with `import vikeReact from 'vike-react/config'` (typically in your /pages/+config.js)" ) -export { default } from './+config.js' +export { config as default } from './+config.js' diff --git a/packages/vike-react/src/types/Config.ts b/packages/vike-react/src/types/Config.ts index 6623a86e..ef4383fa 100644 --- a/packages/vike-react/src/types/Config.ts +++ b/packages/vike-react/src/types/Config.ts @@ -1,17 +1,9 @@ -// https://vike.dev/meta#typescript -import type { - ImportString, - PageContextClient, - // Rename it to `PageContext_` to be able to reference it from within `namespace Vike` - // - https://stackoverflow.com/questions/46559021/typescript-use-of-global-type-inside-namespace-with-same-type - // - https://github.com/Microsoft/TypeScript/issues/983 - PageContext as PageContext_, - PageContextServer -} from 'vike/types' +import type { ImportString, PageContextServer, PageContext, PageContextClient } from 'vike/types' import type { TagAttributes } from '../utils/getTagAttributesString.js' import type { Viewport } from '../renderer/onRenderHtml.js' import type { ConfigsCumulative } from '../hooks/useConfig/configsCumulative.js' +// https://vike.dev/meta#typescript declare global { namespace Vike { interface Config { @@ -211,6 +203,11 @@ declare global { } } +// Be able to reference it from within `namespace Vike` +// - https://stackoverflow.com/questions/46559021/typescript-use-of-global-type-inside-namespace-with-same-type +// - https://github.com/Microsoft/TypeScript/issues/983 +type PageContext_ = PageContext + export type Head = React.ReactNode | (() => React.ReactNode) type Wrapper = (props: { children: React.ReactNode }) => React.ReactNode type Layout = Wrapper diff --git a/packages/vike-react/src/types/index.ts b/packages/vike-react/src/types/index.ts deleted file mode 100644 index f69328a7..00000000 --- a/packages/vike-react/src/types/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -import './PageContext.js' -import './Config.js'