css-typed-vars 0.4.2 → 0.4.3
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/dist/chunk-LYWWAGNR.js +65 -0
- package/dist/esbuild.cjs +43 -35
- package/dist/esbuild.js +1 -1
- package/dist/rollup.cjs +43 -35
- package/dist/rollup.js +1 -1
- package/dist/unplugin.cjs +43 -35
- package/dist/unplugin.js +1 -1
- package/dist/vite.cjs +43 -35
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +43 -35
- package/dist/webpack.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-7PBWBCVY.js +0 -57
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__dirname,
|
|
3
|
+
generateDeclaration,
|
|
4
|
+
generateJs,
|
|
5
|
+
scanVarNames
|
|
6
|
+
} from "./chunk-Y6U2ERL3.js";
|
|
7
|
+
|
|
8
|
+
// src/unplugin.ts
|
|
9
|
+
import { createUnplugin } from "unplugin";
|
|
10
|
+
import { writeFile } from "fs/promises";
|
|
11
|
+
import { join, resolve } from "path";
|
|
12
|
+
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
13
|
+
var RESOLVED_ID = "\0css-typed-vars/vars";
|
|
14
|
+
function getDtsPath(options) {
|
|
15
|
+
if (options.dts === false) return null;
|
|
16
|
+
return options.dts ? resolve(process.cwd(), options.dts) : join(__dirname, "generated.d.ts");
|
|
17
|
+
}
|
|
18
|
+
var unplugin_default = createUnplugin((options) => {
|
|
19
|
+
let cachedNames = null;
|
|
20
|
+
return {
|
|
21
|
+
name: "css-typed-vars",
|
|
22
|
+
vite: {
|
|
23
|
+
enforce: "pre",
|
|
24
|
+
configureServer(server) {
|
|
25
|
+
const handle = async (file) => {
|
|
26
|
+
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
27
|
+
cachedNames = null;
|
|
28
|
+
const names = await scanVarNames(options.input, options.exclude, options.selectors);
|
|
29
|
+
const dtsPath = getDtsPath(options);
|
|
30
|
+
if (dtsPath) {
|
|
31
|
+
await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
32
|
+
}
|
|
33
|
+
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
34
|
+
if (mod) {
|
|
35
|
+
server.moduleGraph.invalidateModule(mod);
|
|
36
|
+
server.ws.send({ type: "full-reload" });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
server.watcher.on("change", handle);
|
|
40
|
+
server.watcher.on("add", handle);
|
|
41
|
+
server.watcher.on("unlink", handle);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
async buildStart() {
|
|
45
|
+
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
46
|
+
const dtsPath = getDtsPath(options);
|
|
47
|
+
if (!dtsPath) return;
|
|
48
|
+
const names = await cachedNames;
|
|
49
|
+
await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
50
|
+
},
|
|
51
|
+
resolveId(id) {
|
|
52
|
+
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
53
|
+
},
|
|
54
|
+
async load(id) {
|
|
55
|
+
if (id === RESOLVED_ID) {
|
|
56
|
+
const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
|
|
57
|
+
return generateJs(names, options.prefix, options.naming);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
unplugin_default
|
|
65
|
+
};
|
package/dist/esbuild.cjs
CHANGED
|
@@ -130,42 +130,50 @@ function getDtsPath(options) {
|
|
|
130
130
|
if (options.dts === false) return null;
|
|
131
131
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
132
132
|
}
|
|
133
|
-
var unplugin_default = (0, import_unplugin.createUnplugin)((options) =>
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
await (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
server.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
133
|
+
var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
134
|
+
let cachedNames = null;
|
|
135
|
+
return {
|
|
136
|
+
name: "css-typed-vars",
|
|
137
|
+
vite: {
|
|
138
|
+
enforce: "pre",
|
|
139
|
+
configureServer(server) {
|
|
140
|
+
const handle = async (file) => {
|
|
141
|
+
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
142
|
+
cachedNames = null;
|
|
143
|
+
const names = await scanVarNames(options.input, options.exclude, options.selectors);
|
|
144
|
+
const dtsPath = getDtsPath(options);
|
|
145
|
+
if (dtsPath) {
|
|
146
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
147
|
+
}
|
|
148
|
+
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
149
|
+
if (mod) {
|
|
150
|
+
server.moduleGraph.invalidateModule(mod);
|
|
151
|
+
server.ws.send({ type: "full-reload" });
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
server.watcher.on("change", handle);
|
|
155
|
+
server.watcher.on("add", handle);
|
|
156
|
+
server.watcher.on("unlink", handle);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
async buildStart() {
|
|
160
|
+
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
161
|
+
const dtsPath = getDtsPath(options);
|
|
162
|
+
if (!dtsPath) return;
|
|
163
|
+
const names = await cachedNames;
|
|
164
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
165
|
+
},
|
|
166
|
+
resolveId(id) {
|
|
167
|
+
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
168
|
+
},
|
|
169
|
+
async load(id) {
|
|
170
|
+
if (id === RESOLVED_ID) {
|
|
171
|
+
const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
|
|
172
|
+
return generateJs(names, options.prefix, options.naming);
|
|
173
|
+
}
|
|
166
174
|
}
|
|
167
|
-
}
|
|
168
|
-
})
|
|
175
|
+
};
|
|
176
|
+
});
|
|
169
177
|
|
|
170
178
|
// src/esbuild.ts
|
|
171
179
|
var esbuild_default = unplugin_default.esbuild;
|
package/dist/esbuild.js
CHANGED
package/dist/rollup.cjs
CHANGED
|
@@ -130,42 +130,50 @@ function getDtsPath(options) {
|
|
|
130
130
|
if (options.dts === false) return null;
|
|
131
131
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
132
132
|
}
|
|
133
|
-
var unplugin_default = (0, import_unplugin.createUnplugin)((options) =>
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
await (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
server.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
133
|
+
var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
134
|
+
let cachedNames = null;
|
|
135
|
+
return {
|
|
136
|
+
name: "css-typed-vars",
|
|
137
|
+
vite: {
|
|
138
|
+
enforce: "pre",
|
|
139
|
+
configureServer(server) {
|
|
140
|
+
const handle = async (file) => {
|
|
141
|
+
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
142
|
+
cachedNames = null;
|
|
143
|
+
const names = await scanVarNames(options.input, options.exclude, options.selectors);
|
|
144
|
+
const dtsPath = getDtsPath(options);
|
|
145
|
+
if (dtsPath) {
|
|
146
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
147
|
+
}
|
|
148
|
+
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
149
|
+
if (mod) {
|
|
150
|
+
server.moduleGraph.invalidateModule(mod);
|
|
151
|
+
server.ws.send({ type: "full-reload" });
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
server.watcher.on("change", handle);
|
|
155
|
+
server.watcher.on("add", handle);
|
|
156
|
+
server.watcher.on("unlink", handle);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
async buildStart() {
|
|
160
|
+
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
161
|
+
const dtsPath = getDtsPath(options);
|
|
162
|
+
if (!dtsPath) return;
|
|
163
|
+
const names = await cachedNames;
|
|
164
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
165
|
+
},
|
|
166
|
+
resolveId(id) {
|
|
167
|
+
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
168
|
+
},
|
|
169
|
+
async load(id) {
|
|
170
|
+
if (id === RESOLVED_ID) {
|
|
171
|
+
const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
|
|
172
|
+
return generateJs(names, options.prefix, options.naming);
|
|
173
|
+
}
|
|
166
174
|
}
|
|
167
|
-
}
|
|
168
|
-
})
|
|
175
|
+
};
|
|
176
|
+
});
|
|
169
177
|
|
|
170
178
|
// src/rollup.ts
|
|
171
179
|
var rollup_default = unplugin_default.rollup;
|
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -128,39 +128,47 @@ function getDtsPath(options) {
|
|
|
128
128
|
if (options.dts === false) return null;
|
|
129
129
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
130
130
|
}
|
|
131
|
-
var unplugin_default = (0, import_unplugin.createUnplugin)((options) =>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
await (
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
server.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
131
|
+
var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
132
|
+
let cachedNames = null;
|
|
133
|
+
return {
|
|
134
|
+
name: "css-typed-vars",
|
|
135
|
+
vite: {
|
|
136
|
+
enforce: "pre",
|
|
137
|
+
configureServer(server) {
|
|
138
|
+
const handle = async (file) => {
|
|
139
|
+
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
140
|
+
cachedNames = null;
|
|
141
|
+
const names = await scanVarNames(options.input, options.exclude, options.selectors);
|
|
142
|
+
const dtsPath = getDtsPath(options);
|
|
143
|
+
if (dtsPath) {
|
|
144
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
145
|
+
}
|
|
146
|
+
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
147
|
+
if (mod) {
|
|
148
|
+
server.moduleGraph.invalidateModule(mod);
|
|
149
|
+
server.ws.send({ type: "full-reload" });
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
server.watcher.on("change", handle);
|
|
153
|
+
server.watcher.on("add", handle);
|
|
154
|
+
server.watcher.on("unlink", handle);
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
async buildStart() {
|
|
158
|
+
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
159
|
+
const dtsPath = getDtsPath(options);
|
|
160
|
+
if (!dtsPath) return;
|
|
161
|
+
const names = await cachedNames;
|
|
162
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
163
|
+
},
|
|
164
|
+
resolveId(id) {
|
|
165
|
+
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
166
|
+
},
|
|
167
|
+
async load(id) {
|
|
168
|
+
if (id === RESOLVED_ID) {
|
|
169
|
+
const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
|
|
170
|
+
return generateJs(names, options.prefix, options.naming);
|
|
171
|
+
}
|
|
164
172
|
}
|
|
165
|
-
}
|
|
166
|
-
})
|
|
173
|
+
};
|
|
174
|
+
});
|
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -130,42 +130,50 @@ function getDtsPath(options) {
|
|
|
130
130
|
if (options.dts === false) return null;
|
|
131
131
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
132
132
|
}
|
|
133
|
-
var unplugin_default = (0, import_unplugin.createUnplugin)((options) =>
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
await (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
server.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
133
|
+
var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
134
|
+
let cachedNames = null;
|
|
135
|
+
return {
|
|
136
|
+
name: "css-typed-vars",
|
|
137
|
+
vite: {
|
|
138
|
+
enforce: "pre",
|
|
139
|
+
configureServer(server) {
|
|
140
|
+
const handle = async (file) => {
|
|
141
|
+
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
142
|
+
cachedNames = null;
|
|
143
|
+
const names = await scanVarNames(options.input, options.exclude, options.selectors);
|
|
144
|
+
const dtsPath = getDtsPath(options);
|
|
145
|
+
if (dtsPath) {
|
|
146
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
147
|
+
}
|
|
148
|
+
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
149
|
+
if (mod) {
|
|
150
|
+
server.moduleGraph.invalidateModule(mod);
|
|
151
|
+
server.ws.send({ type: "full-reload" });
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
server.watcher.on("change", handle);
|
|
155
|
+
server.watcher.on("add", handle);
|
|
156
|
+
server.watcher.on("unlink", handle);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
async buildStart() {
|
|
160
|
+
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
161
|
+
const dtsPath = getDtsPath(options);
|
|
162
|
+
if (!dtsPath) return;
|
|
163
|
+
const names = await cachedNames;
|
|
164
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
165
|
+
},
|
|
166
|
+
resolveId(id) {
|
|
167
|
+
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
168
|
+
},
|
|
169
|
+
async load(id) {
|
|
170
|
+
if (id === RESOLVED_ID) {
|
|
171
|
+
const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
|
|
172
|
+
return generateJs(names, options.prefix, options.naming);
|
|
173
|
+
}
|
|
166
174
|
}
|
|
167
|
-
}
|
|
168
|
-
})
|
|
175
|
+
};
|
|
176
|
+
});
|
|
169
177
|
|
|
170
178
|
// src/vite.ts
|
|
171
179
|
var vite_default = unplugin_default.vite;
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -130,42 +130,50 @@ function getDtsPath(options) {
|
|
|
130
130
|
if (options.dts === false) return null;
|
|
131
131
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
132
132
|
}
|
|
133
|
-
var unplugin_default = (0, import_unplugin.createUnplugin)((options) =>
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
await (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
server.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
133
|
+
var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
134
|
+
let cachedNames = null;
|
|
135
|
+
return {
|
|
136
|
+
name: "css-typed-vars",
|
|
137
|
+
vite: {
|
|
138
|
+
enforce: "pre",
|
|
139
|
+
configureServer(server) {
|
|
140
|
+
const handle = async (file) => {
|
|
141
|
+
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
142
|
+
cachedNames = null;
|
|
143
|
+
const names = await scanVarNames(options.input, options.exclude, options.selectors);
|
|
144
|
+
const dtsPath = getDtsPath(options);
|
|
145
|
+
if (dtsPath) {
|
|
146
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
147
|
+
}
|
|
148
|
+
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
149
|
+
if (mod) {
|
|
150
|
+
server.moduleGraph.invalidateModule(mod);
|
|
151
|
+
server.ws.send({ type: "full-reload" });
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
server.watcher.on("change", handle);
|
|
155
|
+
server.watcher.on("add", handle);
|
|
156
|
+
server.watcher.on("unlink", handle);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
async buildStart() {
|
|
160
|
+
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
161
|
+
const dtsPath = getDtsPath(options);
|
|
162
|
+
if (!dtsPath) return;
|
|
163
|
+
const names = await cachedNames;
|
|
164
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
165
|
+
},
|
|
166
|
+
resolveId(id) {
|
|
167
|
+
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
168
|
+
},
|
|
169
|
+
async load(id) {
|
|
170
|
+
if (id === RESOLVED_ID) {
|
|
171
|
+
const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
|
|
172
|
+
return generateJs(names, options.prefix, options.naming);
|
|
173
|
+
}
|
|
166
174
|
}
|
|
167
|
-
}
|
|
168
|
-
})
|
|
175
|
+
};
|
|
176
|
+
});
|
|
169
177
|
|
|
170
178
|
// src/webpack.ts
|
|
171
179
|
var webpack_default = unplugin_default.webpack;
|
package/dist/webpack.js
CHANGED
package/package.json
CHANGED
package/dist/chunk-7PBWBCVY.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__dirname,
|
|
3
|
-
generateDeclaration,
|
|
4
|
-
generateJs,
|
|
5
|
-
scanVarNames
|
|
6
|
-
} from "./chunk-Y6U2ERL3.js";
|
|
7
|
-
|
|
8
|
-
// src/unplugin.ts
|
|
9
|
-
import { createUnplugin } from "unplugin";
|
|
10
|
-
import { writeFile } from "fs/promises";
|
|
11
|
-
import { join, resolve } from "path";
|
|
12
|
-
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
13
|
-
var RESOLVED_ID = "\0css-typed-vars/vars";
|
|
14
|
-
function getDtsPath(options) {
|
|
15
|
-
if (options.dts === false) return null;
|
|
16
|
-
return options.dts ? resolve(process.cwd(), options.dts) : join(__dirname, "generated.d.ts");
|
|
17
|
-
}
|
|
18
|
-
var unplugin_default = createUnplugin((options) => ({
|
|
19
|
-
name: "css-typed-vars",
|
|
20
|
-
vite: {
|
|
21
|
-
enforce: "pre",
|
|
22
|
-
configureServer(server) {
|
|
23
|
-
server.watcher.on("change", async (file) => {
|
|
24
|
-
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
25
|
-
const names = await scanVarNames(options.input, options.exclude, options.selectors);
|
|
26
|
-
const dtsPath = getDtsPath(options);
|
|
27
|
-
if (dtsPath) {
|
|
28
|
-
await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
29
|
-
}
|
|
30
|
-
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
31
|
-
if (mod) {
|
|
32
|
-
server.moduleGraph.invalidateModule(mod);
|
|
33
|
-
server.ws.send({ type: "full-reload" });
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
async buildStart() {
|
|
39
|
-
const dtsPath = getDtsPath(options);
|
|
40
|
-
if (!dtsPath) return;
|
|
41
|
-
const names = await scanVarNames(options.input, options.exclude, options.selectors);
|
|
42
|
-
await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
43
|
-
},
|
|
44
|
-
resolveId(id) {
|
|
45
|
-
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
46
|
-
},
|
|
47
|
-
async load(id) {
|
|
48
|
-
if (id === RESOLVED_ID) {
|
|
49
|
-
const names = await scanVarNames(options.input, options.exclude, options.selectors);
|
|
50
|
-
return generateJs(names, options.prefix, options.naming);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
|
-
export {
|
|
56
|
-
unplugin_default
|
|
57
|
-
};
|