one
Version:
One is a new React Framework that makes Vite serve both native and web.
28 lines (27 loc) • 1.54 kB
JavaScript
import { CSS_PRELOAD_JS_POSTFIX, isNative, LOADER_JS_POSTFIX, LOADER_JS_POSTFIX_REGEX, PRELOAD_JS_POSTFIX } from "../constants.mjs";
import { getURL } from "../getURL.mjs";
import { removeSearch } from "./removeSearch.mjs";
function cleanUrl(path) {
return removeSearch(path).replace(/\/$/, "").replaceAll("_", "__").replaceAll("/", "_");
}
const isClient = typeof window !== "undefined";
const clientSideURL = isClient ? getURL() : "";
function getPreloadPath(currentPath) {
return `${clientSideURL}/assets/${cleanUrl(currentPath.slice(1))}${PRELOAD_JS_POSTFIX}`;
}
function getPreloadCSSPath(currentPath) {
return `${clientSideURL}/assets/${cleanUrl(currentPath.slice(1))}${CSS_PRELOAD_JS_POSTFIX}`;
}
function getLoaderPath(currentPath, includeUrl = isNative, cacheBust) {
const baseURL = includeUrl ? getURL() : "";
const devPath = process.env.NODE_ENV === "development" ? "/_one" : "";
const currentPathUrl = new URL(currentPath, "http://example.com");
const cleanedUrl = cleanUrl(currentPathUrl.pathname.slice(1));
const cacheBustSegment = cacheBust ? `_refetch_${cacheBust}_` : "";
return `${baseURL}${devPath}/assets/${cleanedUrl}${cacheBustSegment}${LOADER_JS_POSTFIX}`;
}
function getPathFromLoaderPath(loaderPath) {
return loaderPath.replace(LOADER_JS_POSTFIX_REGEX, "").replace(/^(\/_one)?\/assets/, "").replace(/_refetch_\d+_?/, "").replace(/__|_/g, match => match === "__" ? "_" : "/");
}
export { getLoaderPath, getPathFromLoaderPath, getPreloadCSSPath, getPreloadPath };
//# sourceMappingURL=cleanUrl.mjs.map