UNPKG

iles

Version:

Vite & Vue powered static site generator with partial hydration

191 lines (190 loc) 5.92 kB
import { ConfigEnv, PluginOption, ResolveFn, UserConfig as ViteOptions, mergeConfig } from "vite"; import { Options, Plugin } from "@vitejs/plugin-vue"; import components from "unplugin-vue-components/vite"; import { PagesApi, PagesOptions } from "@islands/pages"; import { MarkdownOptions } from "@islands/mdx"; import { GetModuleInfo } from "rolldown"; import { Options as Options$1 } from "unplugin-vue-components/types"; import { Options as Options$2 } from "vite-plugin-solid"; import { Options as SvelteOptions } from "@sveltejs/vite-plugin-svelte"; import { PreactPluginOptions as PreactOptions } from "@preact/preset-vite"; import { RouteParams } from "vue-router"; //#region types/shared.d.ts type SolidOptions = Partial<Options$2>; interface StaticPath<T = Record<string, any>> { params: RouteParams; props: T; } interface RouteToRender { path: string; ssrProps: StaticPath['props']; outputFilename: string; rendered: string; } interface NamedPlugins { pages: { api: PagesApi; }; vue: ReturnType<typeof Plugin>; components: ReturnType<typeof components>; } interface SSGContext { config: AppConfig; pages: RouteToRender[]; } interface BaseIlesConfig extends PagesOptions { /** * Configuration options for Vite.js */ vite: ViteOptions; /** * Configuration options for @vitejs/plugin-vue */ vue: Options; /** * Configuration options for unplugin-vue-components, which manages automatic * imports for components in Vue and MDX files. */ components: Options$1; /** * Configuration options for @preact/preset-vite */ preact?: boolean | PreactOptions; /** * Configuration options for vite-plugin-solid */ solid?: boolean | SolidOptions; /** * Configuration options for @sveltejs/vite-plugin-svelte */ svelte?: boolean | SvelteOptions; /** * Configuration options for markdown processing in îles, including remark * and rehype plugins. */ markdown: MarkdownOptions; /** * Options for iles build. */ ssg: { /** * This hook will be invoked before îles renders a page. * Plugins may alter the rendered HTML */ beforePageRender?: (page: RouteToRender, config: AppConfig) => RouteToRender | void | Promise<void | RouteToRender>; /** * This hook will be invoked once îles has bundled client, SSR, and islands. */ onSiteBundled?: (context: SSGContext) => void | Promise<void>; /** * This hook will be invoked once îles has rendered the entire site. */ onSiteRendered?: (context: SSGContext) => void | Promise<void>; /** * Allows to configure how JS chunks for islands should be grouped. */ manualChunks?: (id: string, meta: { getModuleInfo: GetModuleInfo; }) => string | void; /** * Whether to generate a sitemap.xml and inject the meta tag referencing it. * NOTE: Must provide siteUrl to enable sitemap generation. * @default true */ sitemap?: boolean; }; } interface IlesModule extends Partial<BaseIlesConfig> { name: string; config?: (config: UserConfig, env: ConfigEnv) => UserConfig | null | void | Promise<UserConfig | null | void>; configResolved?: (config: AppConfig, env: ConfigEnv) => void | Promise<void>; } type IlesModuleLike = IlesModule | IlesModule[] | false | null | undefined; type IlesModuleOption = IlesModuleLike | Promise<IlesModuleLike> | string | [string, any]; interface RequiredConfig { /** * URL for site in production, used to generate absolute URLs for sitemap.xml * and social meta tags. Available as `site.url` and `site.canonical`. * @type {string} */ siteUrl: string; /** * Whether to enable SPA-like navigation by avoiding full-page reloads. * @default false */ turbo: boolean; /** * Whether to output more information about islands and hydration in development. * @default true */ debug: boolean | 'log'; /** * Which framework to use to process `.jsx` and `.tsx` files. */ jsx?: 'vue' | 'preact' | 'solid'; /** * Whether to skip `.html` in hrefs and router paths. * @default true */ prettyUrls: boolean; /** * Specify the output directory (relative to project root). * @default 'dist' */ outDir: string; /** * Specify the pages directory (relative to srcDir). * @default 'pages' */ pagesDir: string; /** * Specify the layouts directory (relative to srcDir). * @default 'layouts' */ layoutsDir: string; /** * Specify the directory where the app source is located (relative to project root). * @default 'src' */ srcDir: string; tempDir: string; /** * Specify the directory to nest generated assets under (relative to outDir). * @default 'assets' */ assetsDir: string; } interface UserConfig extends Partial<RequiredConfig>, Partial<IlesModule> { /** * Whether to display drafts in documents and pages. */ drafts?: boolean; modules?: IlesModuleOption[]; } interface AppConfig extends RequiredConfig, Omit<BaseIlesConfig, 'pagesDir'> { base: string; root: string; drafts: boolean; configPath: string; modules: IlesModule[]; namedPlugins: NamedPlugins; vitePlugins: PluginOption[]; resolvePath: ResolveFn; } //#endregion //#region src/node/plugin/plugin.d.ts declare function IslandsPlugins(appConfig: AppConfig): PluginOption[]; //#endregion //#region src/node/constants.d.ts declare const ILES_APP_ENTRY = "/@iles-entry"; //#endregion //#region src/node/build/build.d.ts declare function build(root: string): Promise<void>; //#endregion //#region src/node/config.d.ts declare function resolveConfig(root?: string, env?: ConfigEnv): Promise<AppConfig>; //#endregion //#region src/node/index.d.ts declare function defineConfig(config: UserConfig): UserConfig; //#endregion export { ILES_APP_ENTRY, type UserConfig, build, IslandsPlugins as default, defineConfig, mergeConfig, resolveConfig };