vite-plugin-react-server
Version:
Vite plugin for React Server Components (RSC)
56 lines (53 loc) • 1.36 kB
JavaScript
/**
* vite-plugin-react-server
* Copyright (c) Nico Brinkkemper
* MIT License
*/
import React__default from 'react';
import { join } from 'node:path';
import { readFileSync } from 'node:fs';
function InlineCssCollector({
children,
cssFiles,
moduleRootPath
}) {
return React__default.createElement(
React__default.Fragment,
null,
cssFiles.map((file, index) => {
if (typeof file === "string") {
let filePath = file;
if (process.env["NODE_ENV"] === "development") {
return React__default.createElement("link", {
key: file,
rel: "stylesheet",
href: filePath
});
}
return React__default.createElement(
"style",
{
key: file,
type: "text/css"
},
readFileSync(join(moduleRootPath, filePath), "utf-8")
);
}
const { type, content, key, path } = file;
return React__default.createElement(
"style",
{
key: key ?? path ?? index,
type: type ?? "text/css",
...process.env["NODE_ENV"] === "development" && {
"data-vite-dev-id": join(moduleRootPath, path)
}
},
content
);
}),
children
);
}
export { InlineCssCollector };
//# sourceMappingURL=css-collector-inline.js.map