UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

49 lines (44 loc) 2.03 kB
import { isNativeEnvironment } from "vxrn"; import { resolvedVirtualEntryId, resolvedVirtualEntryIdNative, virtualEntryId, virtualEntryIdNative } from "./virtualEntryConstants.mjs"; import { API_ROUTE_GLOB_PATTERN, ROUTE_GLOB_PATTERN, ROUTE_NATIVE_EXCLUSION_GLOB_PATTERNS, ROUTE_WEB_EXCLUSION_GLOB_PATTERNS } from "../../router/glob-patterns.mjs"; const USE_ONE_SETUP_FILE = ` if (process.env.ONE_SETUP_FILE) { import(/* @vite-ignore */ process.env.ONE_SETUP_FILE) } `; function createVirtualEntry(options) { const routeGlobs = [`/${options.root}/${ROUTE_GLOB_PATTERN}`, ...(options.router?.ignoredRouteFiles?.map(pattern => `!/${options.root}/${pattern}`) || [])], apiRouteGlobs = `/${options.root}/${API_ROUTE_GLOB_PATTERN}`; return { name: "one-virtual-entry", enforce: "pre", resolveId(id) { if (id === virtualEntryId) return resolvedVirtualEntryId; if (id === virtualEntryIdNative) return resolvedVirtualEntryIdNative; }, load(id) { if (id === resolvedVirtualEntryId) return ` ${isNativeEnvironment(this.environment) ? "" : USE_ONE_SETUP_FILE} import { createApp } from 'one' // globbing ${JSON.stringify(routeGlobs)} export default createApp({ routes: import.meta.glob(${JSON.stringify([...routeGlobs, ...ROUTE_WEB_EXCLUSION_GLOB_PATTERNS.map(p => `!${p}`)])}, { exhaustive: true }), routerRoot: ${JSON.stringify(options.root)}, flags: ${JSON.stringify(options.flags)}, }) `; if (id === resolvedVirtualEntryIdNative) return ` ${isNativeEnvironment(this.environment) ? "" : USE_ONE_SETUP_FILE} import { createApp } from 'one' // globbing ${JSON.stringify(routeGlobs)} export default createApp({ routes: import.meta.glob(${JSON.stringify([...routeGlobs, ...ROUTE_NATIVE_EXCLUSION_GLOB_PATTERNS.map(p => `!${p}`), `!${apiRouteGlobs}`])}, { exhaustive: true }), routerRoot: ${JSON.stringify(options.root)}, flags: ${JSON.stringify(options.flags)}, }) `; } }; } export { createVirtualEntry }; //# sourceMappingURL=virtualEntryPlugin.mjs.map