@tailwindcss/vite 0.0.0-development.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.
@@ -0,0 +1,5 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ declare function tailwindcss(): Plugin[];
4
+
5
+ export { tailwindcss as default };
package/dist/index.mjs ADDED
@@ -0,0 +1,115 @@
1
+ // src/index.ts
2
+ import { IO, Parsing, parseCandidateStrings } from "@tailwindcss/oxide";
3
+ import path from "path";
4
+ import { compile, optimizeCss, preflight } from "tailwindcss";
5
+ function tailwindcss() {
6
+ let server = null;
7
+ let candidates = /* @__PURE__ */ new Set();
8
+ let cssModules = /* @__PURE__ */ new Set();
9
+ function updateCssModules() {
10
+ if (!server)
11
+ return;
12
+ let updates = [];
13
+ for (let id of cssModules) {
14
+ let cssModule = server.moduleGraph.getModuleById(id);
15
+ if (!cssModule) {
16
+ console.log("Could not find css module", id);
17
+ continue;
18
+ }
19
+ server.moduleGraph.invalidateModule(cssModule);
20
+ updates.push({
21
+ type: `${cssModule.type}-update`,
22
+ path: cssModule.url,
23
+ acceptedPath: cssModule.url,
24
+ timestamp: Date.now()
25
+ });
26
+ }
27
+ if (updates.length > 0) {
28
+ server.ws.send({ type: "update", updates });
29
+ }
30
+ }
31
+ function scan(src, extension) {
32
+ for (let candidate of parseCandidateStrings(
33
+ [{ content: src, extension }],
34
+ IO.Sequential | Parsing.Sequential
35
+ )) {
36
+ if (candidate.includes("${")) {
37
+ continue;
38
+ }
39
+ candidates.add(candidate);
40
+ }
41
+ }
42
+ function generateCss(css) {
43
+ return css.replace("@tailwind;", optimizeCss(preflight + compile(Array.from(candidates))));
44
+ }
45
+ let initialScan = function() {
46
+ let delayInMs = 100;
47
+ let timer;
48
+ let resolve;
49
+ let resolved = false;
50
+ return {
51
+ tick() {
52
+ if (resolved)
53
+ return;
54
+ timer && clearTimeout(timer);
55
+ timer = setTimeout(resolve, delayInMs);
56
+ },
57
+ complete: new Promise((_resolve) => {
58
+ resolve = () => {
59
+ resolved = true;
60
+ _resolve();
61
+ };
62
+ })
63
+ };
64
+ }();
65
+ return [
66
+ {
67
+ // Step 1: Scan source files for candidates
68
+ name: "@tailwindcss/vite:scan",
69
+ enforce: "pre",
70
+ configureServer(_server) {
71
+ server = _server;
72
+ },
73
+ // Scan index.html for candidates
74
+ transformIndexHtml(html) {
75
+ initialScan.tick();
76
+ scan(html, "html");
77
+ if (server) {
78
+ updateCssModules();
79
+ }
80
+ },
81
+ // Scan all other files for candidates
82
+ transform(src, id) {
83
+ if (id.includes("/.vite/"))
84
+ return;
85
+ let [filename] = id.split("?", 2);
86
+ let extension = path.extname(filename).slice(1);
87
+ if (extension === "" || extension === "css")
88
+ return;
89
+ initialScan.tick();
90
+ scan(src, extension);
91
+ if (server) {
92
+ updateCssModules();
93
+ }
94
+ }
95
+ },
96
+ {
97
+ // Step 2: Generate CSS
98
+ name: "@tailwindcss/vite:generate",
99
+ async transform(src, id) {
100
+ let [filename] = id.split("?", 2);
101
+ let extension = path.extname(filename).slice(1);
102
+ if (extension !== "css")
103
+ return;
104
+ if (!src.includes("@tailwind"))
105
+ return;
106
+ cssModules.add(id);
107
+ await initialScan.complete;
108
+ return { code: generateCss(src) };
109
+ }
110
+ }
111
+ ];
112
+ }
113
+ export {
114
+ tailwindcss as default
115
+ };
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@tailwindcss/vite",
3
+ "version": "0.0.0-development.1",
4
+ "scripts": {
5
+ "build": "tsup-node ./src/index.ts --format esm --dts",
6
+ "dev": "npm run build -- --watch"
7
+ },
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.mts",
14
+ "import": "./dist/index.mjs"
15
+ }
16
+ },
17
+ "dependencies": {
18
+ "tailwindcss": "0.0.0-development.1",
19
+ "@tailwindcss/oxide": "0.0.0-development.1"
20
+ }
21
+ }