@barocss/server 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ const tag = ssrStyleTag(css); // '<style data-barocss-ssr>…</style>': put it i
|
|
|
38
38
|
The output never contains `@layer` statements.
|
|
39
39
|
- The result is one ordered sheet (#267): each referenced theme var once, each `@property` block once, rules in Tailwind variant order.
|
|
40
40
|
- Also exported: `ssrStyleTag(css, { nonce })`, `SSR_STYLE_ATTRIBUTE`.
|
|
41
|
+
- **Inlining CSS into HTML: use the helper.** Wrap server output with `ssrStyleTag(css)` (or, where a framework takes a string, apply the same end-tag escaping as the Next.js example below). Never interpolate raw CSS into `<style>${css}</style>`.
|
|
41
42
|
|
|
42
43
|
**Next.js App Router** (a server component; `html` is the CMS or model markup you render):
|
|
43
44
|
|
|
@@ -54,12 +55,20 @@ export default async function Page() {
|
|
|
54
55
|
}
|
|
55
56
|
```
|
|
56
57
|
|
|
57
|
-
Don't give this `<style>` a `precedence` or `href`, so React leaves it where it is. It only has to come before the content it styles. When you render components rather than an HTML string, pass the class list instead: `runtime.generateCssForHtml(['p-4 sm:p-6', …], { skip: BUILD_CSS })`.
|
|
58
|
+
The `.replace(/<\/style/gi, '<\\/style')` is what `ssrStyleTag` does for you: raw CSS inlined into HTML must never contain a markup end-tag sequence, or it could close the `<style>` element early. Don't give this `<style>` a `precedence` or `href`, so React leaves it where it is. It only has to come before the content it styles. When you render components rather than an HTML string, pass the class list instead: `runtime.generateCssForHtml(['p-4 sm:p-6', …], { skip: BUILD_CSS })`.
|
|
58
59
|
|
|
59
60
|
**Astro, SSR** (`src/middleware.ts`; read the emitted build CSS once at startup):
|
|
60
61
|
|
|
61
62
|
```ts
|
|
62
63
|
import { defineMiddleware } from 'astro:middleware';
|
|
64
|
+
import { ServerRuntime, ssrStyleTag } from '@barocss/server';
|
|
65
|
+
const runtime = new ServerRuntime({
|
|
66
|
+
cssVarPrefix: 'tw', // always, next to a Tailwind build
|
|
67
|
+
// from the build's `@custom-variant dark (...)`: shadcn -> '.dark &',
|
|
68
|
+
// `[data-theme=dark]` variant -> '[data-theme=dark] &', none -> omit (default 'media')
|
|
69
|
+
darkMode: 'class',
|
|
70
|
+
darkModeSelector: '.dark &',
|
|
71
|
+
});
|
|
63
72
|
const dir = path.resolve('dist/client/_astro');
|
|
64
73
|
const BUILD_CSS = fs.existsSync(dir) ? fs.readdirSync(dir).filter((f) => f.endsWith('.css')).map((f) => fs.readFileSync(path.join(dir, f), 'utf8')).join('\n') : '';
|
|
65
74
|
|
|
@@ -74,7 +83,7 @@ export const onRequest = defineMiddleware(async (_ctx, next) => {
|
|
|
74
83
|
});
|
|
75
84
|
```
|
|
76
85
|
|
|
77
|
-
**Astro, static output:** do the same once in an integration's `astro:build:done` hook: read every `.css` under `dir` as the skip CSS, then rewrite every `.html`. The full recipe (shared config, static hook, client companion) is in the docs: `guide/integration/astro`.
|
|
86
|
+
**Astro, static output:** do the same once in an integration's `astro:build:done` hook: read every `.css` under `dir` as the skip CSS, then rewrite every `.html`, with the same `cssVarPrefix: 'tw'` and `darkModeSelector` on the `ServerRuntime`. The full recipe (shared config, static hook, client companion) is in the docs: `guide/integration/astro`.
|
|
78
87
|
|
|
79
88
|
**Config to copy from the build CSS** (use the same object on server and client):
|
|
80
89
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barocss/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/barocss/barocss.git",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"jsdom": "^26.1.0",
|
|
29
|
-
"@barocss/kit": "0.
|
|
29
|
+
"@barocss/kit": "0.8.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"vite": "^7.1.3",
|
|
33
33
|
"vite-plugin-dts": "^4.5.4",
|
|
34
|
-
"vitest": "^
|
|
34
|
+
"vitest": "^5.0.2"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "vite build",
|