( config: TinyPagesConfig, createBuildPlugins )
| 62 | } |
| 63 | |
| 64 | export async function createBuildContext( |
| 65 | config: TinyPagesConfig, |
| 66 | createBuildPlugins |
| 67 | ): Promise<[BuildContext, ViteDevServer]> { |
| 68 | buildContext = { |
| 69 | utils: { |
| 70 | logger: createLogger(config.vite.logLevel, { prefix: "[tinypages]" }), |
| 71 | invalidate: (input: string) => purgeComponentCache(input), |
| 72 | pageDir: path.join(config.vite.root, "pages"), |
| 73 | stylesDir: path.join(config.vite.root, "styles"), |
| 74 | i18nDir: path.join(config.vite.root, "locales"), |
| 75 | kit: pluginKit(config.modules), |
| 76 | }, |
| 77 | config, |
| 78 | virtualModuleMap: new Map([ |
| 79 | [ |
| 80 | "/uno:only.js", |
| 81 | "import 'uno.css';import {router} from 'million/router';router('body')", |
| 82 | ], |
| 83 | ]), |
| 84 | fileToHtmlMap: new Map(), |
| 85 | fileToURLMap: new Map(), |
| 86 | seenURLs: new Set(), |
| 87 | postFS: {}, |
| 88 | isRebuild: false, |
| 89 | isSmallPageBuild: false, |
| 90 | }; |
| 91 | |
| 92 | /** |
| 93 | * Hook: defineConfig build |
| 94 | */ |
| 95 | await buildContext.utils.kit.defineConfig(config); |
| 96 | |
| 97 | let plugins = await createBuildPlugins(); |
| 98 | |
| 99 | if (buildContext.config.vite.plugins) { |
| 100 | buildContext.config.vite.plugins.push(plugins); |
| 101 | vite = await createServer({ ...buildContext.config.vite }); |
| 102 | } else { |
| 103 | vite = await createServer({ ...buildContext.config.vite, plugins }); |
| 104 | } |
| 105 | |
| 106 | return [buildContext, vite]; |
| 107 | } |
| 108 | |
| 109 | type DevOrIso = "dev" | "iso"; |
| 110 | type BuildOrDev<T extends DevOrIso> = T extends "dev" |
no test coverage detected