Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 3744214

Browse files
committed
Update UnoConfig types
1 parent d0eba00 commit 3744214

File tree

7 files changed

+27
-25
lines changed

7 files changed

+27
-25
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { serve } from "aleph/server";
2-
import unocss from "aleph/unocss";
3-
import init, { ssr } from "./pkg/server.js";
2+
import UnoCSS from "aleph/unocss";
43
import config from "./unocss.config.ts";
4+
import init, { ssr } from "./pkg/server.js";
55

66
const wasmUrl = new URL("./pkg/server_bg.wasm", import.meta.url);
77
await init(await Deno.readFile(wasmUrl));
88

99
serve({
1010
baseUrl: import.meta.url,
11-
atomicCSS: unocss(/\.rs$/, config),
11+
atomicCSS: UnoCSS(/\.rs$/, config),
1212
ssr: ({ url }) => ssr(url.href),
1313
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { serve } from "aleph/react-server";
2-
import unocss from "aleph/unocss";
3-
import routes from "./routes/_export.ts";
2+
import UnoCSS from "aleph/unocss";
43
import config from "./unocss.config.ts";
4+
import routes from "./routes/_export.ts";
55

66
serve({
77
baseUrl: import.meta.url,
88
router: { routes },
9-
atomicCSS: unocss(config),
9+
atomicCSS: UnoCSS({ ...config, resetCSS: false }),
1010
ssr: true,
1111
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { serve } from "aleph/solid-server";
2-
import unocss from "aleph/unocss";
3-
import routes from "./routes/_export.ts";
2+
import UnoCSS from "aleph/unocss";
43
import config from "./unocss.config.ts";
4+
import routes from "./routes/_export.ts";
55

66
serve({
77
baseUrl: import.meta.url,
88
router: { routes },
9-
atomicCSS: unocss(config),
9+
atomicCSS: UnoCSS(config),
1010
ssr: true,
1111
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { serve } from "aleph/server";
2-
import unocss from "aleph/unocss";
3-
import init, { ssr } from "./pkg/yew_app.js";
2+
import UnoCSS from "aleph/unocss";
43
import config from "./unocss.config.ts";
4+
import init, { ssr } from "./pkg/yew_app.js";
55

66
const wasmUrl = new URL("./pkg/yew_app_bg.wasm", import.meta.url);
77
await init(await Deno.readFile(wasmUrl));
88

99
serve({
1010
baseUrl: import.meta.url,
11-
atomicCSS: unocss(/\.rs$/, config),
11+
atomicCSS: UnoCSS(/\.rs$/, config),
1212
ssr: ({ url }) => ssr(url.href),
1313
});

server/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import log from "./log.ts";
66
import { getContentType } from "./media_type.ts";
77
import type { AlephConfig, CookieOptions, ImportMap, JSXConfig } from "./types.ts";
88

9-
export const regJsxFile = /\.(jsx|tsx)$/;
9+
export const regJsxFile = /\.(jsx|tsx|mdx)$/;
1010
export const regFullVersion = /@\d+\.\d+\.\d+/;
1111
export const builtinModuleExts = ["tsx", "ts", "mts", "jsx", "js", "mjs"];
1212

server/transformer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ export default {
203203
const styleTs = `${alephPkgUri}/runtime/core/style.ts`;
204204
// embed module unocss css in dev mode
205205
if (isDev && config?.atomicCSS) {
206-
const regexp = config.atomicCSS.test ?? regJsxFile;
207-
if (regexp.test(pathname)) {
206+
const re = config.atomicCSS.test ?? regJsxFile;
207+
if (re.test(pathname)) {
208208
try {
209209
const { css, matched } = await config.atomicCSS.generate(source, {
210210
id: specifier,

server/unocss.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { createGenerator, type UnoGenerator, type UserConfig } from "@unocss/core";
22
import type { AtomicCSSConfig } from "./types.ts";
33

4-
type UnoConfig = UserConfig & AtomicCSSConfig;
4+
type UnoConfig = UserConfig & { test?: RegExp; resetCSS?: boolean };
55

6-
export default function unocss(config: UnoConfig): UnoGenerator & AtomicCSSConfig;
7-
export default function unocss(test: RegExp, config: UnoConfig): UnoGenerator & AtomicCSSConfig;
8-
export default function unocss(
6+
export default function UnoCSS(config: UnoConfig): UnoGenerator & AtomicCSSConfig;
7+
export default function UnoCSS(test: RegExp, config: UnoConfig): UnoGenerator & AtomicCSSConfig;
8+
export default function UnoCSS(
99
testOrConfig: RegExp | UnoConfig,
1010
config?: UnoConfig,
1111
): UnoGenerator & AtomicCSSConfig {
@@ -18,13 +18,15 @@ export default function unocss(
1818
if (test) {
1919
Reflect.set(generator, "test", test);
2020
}
21-
if (config.test) {
21+
if (config.test instanceof RegExp) {
2222
Reflect.set(generator, "test", config.test);
2323
}
24-
Reflect.set(
25-
generator,
26-
"resetCSS",
27-
`https://esm.sh/@unocss/reset@${generator.version}/${config.resetCSS ?? "tailwind"}.css`,
28-
);
24+
if (config.resetCSS !== false) {
25+
Reflect.set(
26+
generator,
27+
"resetCSS",
28+
`https://esm.sh/@unocss/reset@${generator.version}/tailwind.css`,
29+
);
30+
}
2931
return generator;
3032
}

0 commit comments

Comments
 (0)