UNPKG

one

Version:

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

35 lines (34 loc) 2.13 kB
import { safeJsonStringify } from "./utils/htmlEscape.mjs"; const isWebClient = typeof window !== "undefined"; const isWebServer = typeof window === "undefined"; const isNative = false; const hasWebHistory = isWebClient && typeof window.history !== "undefined" && typeof window.location !== "undefined"; let CACHE_KEY = `${process.env.ONE_CACHE_KEY ?? Math.round(Math.random() * 1e8)}`; const LOADER_JS_POSTFIX_UNCACHED = `_vxrn_loader.js`; const LOADER_JS_POSTFIX_REGEX_STRING = `_\\d+${LOADER_JS_POSTFIX_UNCACHED}$`; const LOADER_JS_POSTFIX_REGEX = new RegExp(LOADER_JS_POSTFIX_REGEX_STRING); let LOADER_JS_POSTFIX = `_${CACHE_KEY}${LOADER_JS_POSTFIX_UNCACHED}`; let PRELOAD_JS_POSTFIX = `_${CACHE_KEY}_preload.js`; let CSS_PRELOAD_JS_POSTFIX = `_${CACHE_KEY}_preload_css.js`; const PRELOAD_JS_POSTFIX_REGEX = /_\d+_preload\.js$/; const CSS_PRELOAD_JS_POSTFIX_REGEX = /_\d+_preload_css\.js$/; function setCacheKey(key) { if (!key || key === CACHE_KEY) return; CACHE_KEY = key; LOADER_JS_POSTFIX = `_${CACHE_KEY}${LOADER_JS_POSTFIX_UNCACHED}`; PRELOAD_JS_POSTFIX = `_${CACHE_KEY}_preload.js`; CSS_PRELOAD_JS_POSTFIX = `_${CACHE_KEY}_preload_css.js`; } const VIRTUAL_SSR_CSS_ENTRY = `virtual:ssr-css.css`; const VIRTUAL_SSR_CSS_HREF = `/@id/__x00__${VIRTUAL_SSR_CSS_ENTRY}`; const SERVER_CONTEXT_KEY = "__one_server_context__"; const getSpaHeaderElements = ({ serverContext = {} } = {}) => ` <script>globalThis['global'] = globalThis<\/script> <script>globalThis['__vxrnIsSPA'] = true<\/script> <script>globalThis["${SERVER_CONTEXT_KEY}"] = ${safeJsonStringify(serverContext)}<\/script> <script>globalThis.__oneLoadedCSS = new Set(${safeJsonStringify(serverContext.css || [])})<\/script> `; export { CACHE_KEY, CSS_PRELOAD_JS_POSTFIX, CSS_PRELOAD_JS_POSTFIX_REGEX, LOADER_JS_POSTFIX, LOADER_JS_POSTFIX_REGEX, LOADER_JS_POSTFIX_REGEX_STRING, LOADER_JS_POSTFIX_UNCACHED, PRELOAD_JS_POSTFIX, PRELOAD_JS_POSTFIX_REGEX, SERVER_CONTEXT_KEY, VIRTUAL_SSR_CSS_ENTRY, VIRTUAL_SSR_CSS_HREF, getSpaHeaderElements, hasWebHistory, isNative, isWebClient, isWebServer, setCacheKey }; //# sourceMappingURL=constants.mjs.map