fully-react
Version:
React Server for Vite
99 lines (96 loc) • 3.13 kB
JavaScript
import {
component
} from "../chunk-ADCXIBIX.js";
// src/server/dev/react-refresh-script.tsx
import { jsx } from "react/jsx-runtime";
var ReactRefreshScript = import.meta.env.DEV ? function ReactRefreshScript2() {
if (!import.meta.env.DEV) {
return null;
}
return /* @__PURE__ */ jsx(
"script",
{
type: "module",
dangerouslySetInnerHTML: {
__html: `
import RefreshRuntime from "/@react-refresh"
RefreshRuntime.injectIntoGlobalHook(window)
window.$RefreshReg$ = () => {}
window.$RefreshSig$ = () => (type) => type
window.__vite_plugin_react_preamble_installed__ = true
`
}
}
);
} : () => null;
// src/shared/assets.tsx
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
var linkProps = [
["js", { rel: "modulepreload", crossOrigin: "" }],
["jsx", { rel: "modulepreload", crossOrigin: "" }],
["ts", { rel: "modulepreload", crossOrigin: "" }],
["tsx", { rel: "modulepreload", crossOrigin: "" }],
["css", { rel: "stylesheet", precedence: "high" }],
["woff", { rel: "preload", as: "font", type: "font/woff", crossOrigin: "" }],
[
"woff2",
{ rel: "preload", as: "font", type: "font/woff2", crossOrigin: "" }
],
["gif", { rel: "preload", as: "image", type: "image/gif" }],
["jpg", { rel: "preload", as: "image", type: "image/jpeg" }],
["jpeg", { rel: "preload", as: "image", type: "image/jpeg" }],
["png", { rel: "preload", as: "image", type: "image/png" }],
["webp", { rel: "preload", as: "image", type: "image/webp" }],
["svg", { rel: "preload", as: "image", type: "image/svg+xml" }],
["ico", { rel: "preload", as: "image", type: "image/x-icon" }],
["avif", { rel: "preload", as: "image", type: "image/avif" }],
["mp4", { rel: "preload", as: "video", type: "video/mp4" }],
["webm", { rel: "preload", as: "video", type: "video/webm" }]
];
var linkPropsMap = new Map(linkProps);
var Asset = ({ file }) => {
const ext = file.split(".").pop();
if (!ext) {
return null;
}
const props = linkPropsMap.get(ext);
if (!props) {
return null;
}
return /* @__PURE__ */ jsx2("link", { href: file, ...props });
};
var Style = ({ style, src }) => {
return /* @__PURE__ */ jsx2(
"style",
{
dangerouslySetInnerHTML: { __html: style },
suppressHydrationWarning: true
}
);
};
var Assets = component(async function Assets2({
assets = []
}) {
if (import.meta.env.SSR) {
const env = globalThis.env;
const allAssets = [
...(/* @__PURE__ */ new Set([...assets, ...await env.findAssets()])).values()
];
return /* @__PURE__ */ jsxs(Fragment, { children: [
allAssets.map((asset, index) => {
if (typeof asset === "string") {
return /* @__PURE__ */ jsx2(Asset, { file: asset }, asset);
} else if (asset.type === "style") {
return /* @__PURE__ */ jsx2(Style, { style: asset.style }, asset.src ?? `${index}`);
}
}),
import.meta.env.DEV ? /* @__PURE__ */ jsx2(ReactRefreshScript, {}) : null
] });
}
return null;
});
export {
Asset,
Assets,
Style
};