( config: TinyPagesConfig, createDevPlugins, source?: string )
| 15 | let buildContext: BuildContext; |
| 16 | |
| 17 | export async function createDevContext( |
| 18 | config: TinyPagesConfig, |
| 19 | createDevPlugins, |
| 20 | source?: string |
| 21 | ): Promise<[DevContext, ViteDevServer]> { |
| 22 | const { islands_cache, markdown_cache } = await createCaches( |
| 23 | config.vite.root, |
| 24 | false |
| 25 | ); |
| 26 | giveComponentCache(islands_cache); |
| 27 | devContext = { |
| 28 | config, |
| 29 | page: presetPageConfig, |
| 30 | utils: { |
| 31 | logger: createLogger(config.vite.logLevel, { prefix: "[tinypages]" }), |
| 32 | async render(html: string) { |
| 33 | return await render(html, vite, devContext); |
| 34 | }, |
| 35 | invalidate: (input: string) => purgeComponentCache(input), |
| 36 | pageDir: path.join(config.vite.root, "pages"), |
| 37 | stylesDir: path.join(config.vite.root, "styles"), |
| 38 | i18nDir: path.join(config.vite.root, "locales"), |
| 39 | currI18n: "", |
| 40 | configFile: source || "", |
| 41 | markdown_cache, |
| 42 | kit: pluginKit(config.modules), |
| 43 | }, |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * Hook: defineConfig (dev) |
| 48 | */ |
| 49 | await devContext.utils.kit.defineConfig(config); |
| 50 | |
| 51 | const plugins = await createDevPlugins(); |
| 52 | if (devContext.config.vite.plugins) { |
| 53 | devContext.config.vite.plugins.push(plugins); |
| 54 | vite = await createServer({ ...devContext.config.vite }); |
| 55 | } else { |
| 56 | vite = await createServer({ |
| 57 | ...devContext.config.vite, |
| 58 | plugins, |
| 59 | }); |
| 60 | } |
| 61 | return [devContext, vite]; |
| 62 | } |
| 63 | |
| 64 | export async function createBuildContext( |
| 65 | config: TinyPagesConfig, |
no test coverage detected