@baybreezy/docd 0.0.5 → 0.0.6
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/app/assets/css/tailwind.css +0 -1
- package/modules/css.ts +21 -14
- package/package.json +1 -1
package/modules/css.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
|
|
1
3
|
import { addVitePlugin, createResolver, defineNuxtModule } from "@nuxt/kit";
|
|
2
|
-
import { joinURL } from "ufo";
|
|
3
4
|
|
|
4
5
|
export default defineNuxtModule({
|
|
5
6
|
meta: {
|
|
@@ -8,24 +9,30 @@ export default defineNuxtModule({
|
|
|
8
9
|
setup(_options, nuxt) {
|
|
9
10
|
const resolver = createResolver(import.meta.url);
|
|
10
11
|
|
|
11
|
-
// Absolute path to the layer's tailwind entry —
|
|
12
|
-
//
|
|
13
|
-
const tailwindCssPath = resolver.resolve("../app/assets/css/tailwind.css");
|
|
12
|
+
// Absolute path to the layer's tailwind entry — resolved from this module's
|
|
13
|
+
// location so it stays correct whether docd is local or installed from npm.
|
|
14
|
+
const tailwindCssPath = resolver.resolve("../app/assets/css/tailwind.css").replace(/\\/g, "/");
|
|
14
15
|
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
const
|
|
16
|
+
// Absolute paths that Tailwind needs to scan.
|
|
17
|
+
const rootDir = nuxt.options.rootDir.replace(/\\/g, "/");
|
|
18
|
+
const layerAppDir = resolver.resolve("../app").replace(/\\/g, "/");
|
|
18
19
|
|
|
19
|
-
//
|
|
20
|
+
// Use the `load` hook rather than `transform` so our modified source is
|
|
21
|
+
// visible to @tailwindcss/vite's transform hook (which has enforce:"pre"
|
|
22
|
+
// and is registered earlier). Vite always runs `load` before `transform`.
|
|
20
23
|
addVitePlugin({
|
|
21
24
|
name: "docd:inject-tailwind-sources",
|
|
22
25
|
enforce: "pre",
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
async load(id) {
|
|
27
|
+
const cleanId = id?.split("?")?.[0]?.replace(/\\/g, "/");
|
|
28
|
+
if (cleanId !== tailwindCssPath) return null;
|
|
29
|
+
|
|
30
|
+
const code = await readFile(tailwindCssPath, "utf8");
|
|
31
|
+
return [
|
|
32
|
+
code,
|
|
33
|
+
`@source ${JSON.stringify(`${rootDir}/**/*`)};`,
|
|
34
|
+
`@source ${JSON.stringify(`${layerAppDir}/**/*`)};`,
|
|
35
|
+
].join("\n");
|
|
29
36
|
},
|
|
30
37
|
});
|
|
31
38
|
|