@baybreezy/docd 0.1.1 → 0.1.2
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/modules/css.ts +38 -0
- package/package.json +1 -1
package/modules/css.ts
CHANGED
|
@@ -36,6 +36,44 @@ export default defineNuxtModule({
|
|
|
36
36
|
},
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
+
// Inject `@reference` into consuming-app CSS files that use `@apply` but
|
|
40
|
+
// don't already import or reference Tailwind. This gives them access to the
|
|
41
|
+
// layer's theme tokens without re-outputting Tailwind's stylesheet.
|
|
42
|
+
addVitePlugin({
|
|
43
|
+
name: "docd:inject-tailwind-reference",
|
|
44
|
+
enforce: "pre",
|
|
45
|
+
async load(id) {
|
|
46
|
+
const cleanId = id?.split("?")?.[0]?.replace(/\\/g, "/");
|
|
47
|
+
|
|
48
|
+
if (!cleanId?.endsWith(".css")) return null;
|
|
49
|
+
// Skip the layer's own tailwind entry — it already has @import "tailwindcss".
|
|
50
|
+
if (cleanId === tailwindCssPath) return null;
|
|
51
|
+
// Only touch files inside the consuming app root, not node_modules or the layer.
|
|
52
|
+
if (!cleanId.startsWith(`${rootDir}/`)) return null;
|
|
53
|
+
if (cleanId.startsWith(`${layerAppDir}/`)) return null;
|
|
54
|
+
|
|
55
|
+
let code: string;
|
|
56
|
+
try {
|
|
57
|
+
code = await readFile(cleanId, "utf8");
|
|
58
|
+
} catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Skip files that already have reference
|
|
63
|
+
if (
|
|
64
|
+
code.includes('@import "tailwindcss"') ||
|
|
65
|
+
code.includes("@import 'tailwindcss'") ||
|
|
66
|
+
code.includes("@reference")
|
|
67
|
+
)
|
|
68
|
+
return null;
|
|
69
|
+
|
|
70
|
+
// Only inject when the file actually uses @apply to avoid unnecessary overhead.
|
|
71
|
+
if (!code.includes("@apply")) return null;
|
|
72
|
+
|
|
73
|
+
return `@reference ${JSON.stringify(tailwindCssPath)};\n${code}`;
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
39
77
|
// Suppress noisy Vite warnings produced during Tailwind's build pass.
|
|
40
78
|
nuxt.hook("vite:extendConfig", (config) => {
|
|
41
79
|
const logger = config.customLogger;
|