Skip to content

Commit 1521791

Browse files
committed
separate tailwind.css; always refresh it in preview; blocklist the grid classes for compatibility
1 parent 65e7676 commit 1521791

File tree

5 files changed

+9
-3
lines changed

5 files changed

+9
-3
lines changed

src/client/preview.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ export function open({hash, eval: compile} = {}) {
155155
for (const href of message.stylesheets.removed) {
156156
document.head.querySelector(`link[rel="stylesheet"][href="${href}"]`)?.remove();
157157
}
158+
const tw = document.head.querySelector('link[rel="stylesheet"][href$="_observablehq/tailwind.css"]');
159+
if (tw) tw.href = "" + tw.href; // reload tailwind.css
158160
}
159161
enableCopyButtons();
160162
break;
File renamed without changes.

src/resolvers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ async function resolveResolvers(
348348
}
349349

350350
// Add implicit stylesheets.
351+
stylesheets.add("observablehq:tailwind.css");
351352
for (const specifier of getImplicitStylesheets(staticImports)) {
352353
stylesheets.add(specifier);
353354
if (specifier.startsWith("npm:")) {

src/rollup.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {THEMES, renderTheme} from "./theme.js";
2020

2121
const STYLE_MODULES = {
2222
"observablehq:default.css": getStylePath("default.css"),
23+
"observablehq:tailwind.css": getStylePath("tailwind.css"),
2324
...Object.fromEntries(THEMES.map(({name, path}) => [`observablehq:theme-${name}.css`, path]))
2425
};
2526

@@ -47,16 +48,18 @@ export async function bundleStyles({
4748
theme?: string[];
4849
root: string;
4950
}): Promise<string> {
51+
const plugins = path === getClientPath("tailwind.css") ? [await tailwindConfig(root)] : undefined;
5052
const result = await build({
5153
bundle: true,
5254
...(path ? {entryPoints: [path]} : {stdin: {contents: renderTheme(theme!), loader: "css"}}),
5355
write: false,
5456
minify,
55-
plugins: [await tailwindConfig(root)],
57+
plugins,
5658
alias: STYLE_MODULES
5759
});
5860
let text = result.outputFiles[0].text;
5961
if (path === getClientPath("stdlib/inputs.css")) text = rewriteInputsNamespace(text);
62+
6063
return text;
6164
}
6265

@@ -215,7 +218,8 @@ export default {
215218
]
216219
},
217220
darkMode: ["variant", "&:where([class~=dark], [class~=dark] *)"],
218-
prefix: 'tw-',
221+
blocklist: ["grid", "grid-cols-2", "grid-cols-3", "grid-cols-4"],
222+
prefix: "",
219223
...config
220224
};
221225
`

src/style/default.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@import url("./tailwind.css");
21
@import url("./global.css");
32
@import url("./layout.css");
43
@import url("./grid.css");

0 commit comments

Comments
 (0)