@unocss/webpack 66.5.10-beta.1 → 66.5.11
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/index-CgVajxkl.d.cts +961 -0
- package/dist/index-DLa_c6IJ.d.mts +961 -0
- package/dist/index.cjs +7 -18
- package/dist/index.d.cts +2 -15
- package/dist/index.d.mts +2 -15
- package/dist/index.mjs +5 -16
- package/dist/rspack.cjs +5 -18
- package/dist/rspack.d.cts +4 -5
- package/dist/rspack.d.mts +4 -5
- package/dist/rspack.mjs +5 -16
- package/dist/unplugin-BuJ92w8F.mjs +431 -0
- package/dist/unplugin-DecJv6sA.cjs +469 -0
- package/package.json +10 -10
- package/dist/index.d.ts +0 -15
- package/dist/rspack.d.ts +0 -7
- package/dist/shared/webpack.CM0t2xuW.mjs +0 -468
- package/dist/shared/webpack.CUaiXpSS.cjs +0 -479
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
let node_path = require("node:path");
|
|
29
|
+
let node_process = require("node:process");
|
|
30
|
+
node_process = __toESM(node_process);
|
|
31
|
+
let node_fs_promises = require("node:fs/promises");
|
|
32
|
+
node_fs_promises = __toESM(node_fs_promises);
|
|
33
|
+
let tinyglobby = require("tinyglobby");
|
|
34
|
+
let _jridgewell_remapping = require("@jridgewell/remapping");
|
|
35
|
+
_jridgewell_remapping = __toESM(_jridgewell_remapping);
|
|
36
|
+
let magic_string = require("magic-string");
|
|
37
|
+
magic_string = __toESM(magic_string);
|
|
38
|
+
let _unocss_core = require("@unocss/core");
|
|
39
|
+
let _unocss_config = require("@unocss/config");
|
|
40
|
+
let unplugin_utils = require("unplugin-utils");
|
|
41
|
+
let node_crypto = require("node:crypto");
|
|
42
|
+
node_crypto = __toESM(node_crypto);
|
|
43
|
+
let pathe = require("pathe");
|
|
44
|
+
let unplugin = require("unplugin");
|
|
45
|
+
let webpack_sources = require("webpack-sources");
|
|
46
|
+
webpack_sources = __toESM(webpack_sources);
|
|
47
|
+
|
|
48
|
+
//#region ../../virtual-shared/integration/src/constants.ts
|
|
49
|
+
const INCLUDE_COMMENT = "@unocss-include";
|
|
50
|
+
const IGNORE_COMMENT = "@unocss-ignore";
|
|
51
|
+
const CSS_PLACEHOLDER = "@unocss-placeholder";
|
|
52
|
+
const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
53
|
+
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
54
|
+
const SKIP_COMMENT_RE = new RegExp(`(\/\/\\s*?${SKIP_START_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_START_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_START_COMMENT}\\s*?-->)[\\s\\S]*?(\/\/\\s*?${SKIP_END_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_END_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_END_COMMENT}\\s*?-->)`, "g");
|
|
55
|
+
const VIRTUAL_ENTRY_ALIAS = [/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/];
|
|
56
|
+
const LAYER_MARK_ALL = "__ALL__";
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region ../../virtual-shared/integration/src/utils.ts
|
|
60
|
+
function getPath(id) {
|
|
61
|
+
return id.replace(/\?.*$/, "");
|
|
62
|
+
}
|
|
63
|
+
function isCssId(id) {
|
|
64
|
+
return _unocss_core.cssIdRE.test(id);
|
|
65
|
+
}
|
|
66
|
+
function hash$1(str) {
|
|
67
|
+
let i;
|
|
68
|
+
let l;
|
|
69
|
+
let hval = 2166136261;
|
|
70
|
+
for (i = 0, l = str.length; i < l; i++) {
|
|
71
|
+
hval ^= str.charCodeAt(i);
|
|
72
|
+
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
73
|
+
}
|
|
74
|
+
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
75
|
+
}
|
|
76
|
+
function transformSkipCode(code, map, SKIP_RULES_RE, keyFlag) {
|
|
77
|
+
for (const item of Array.from(code.matchAll(SKIP_RULES_RE))) if (item != null) {
|
|
78
|
+
const matched = item[0];
|
|
79
|
+
const withHashKey = `${keyFlag}${hash$1(matched)}`;
|
|
80
|
+
map.set(withHashKey, matched);
|
|
81
|
+
code = code.replace(matched, withHashKey);
|
|
82
|
+
}
|
|
83
|
+
return code;
|
|
84
|
+
}
|
|
85
|
+
function restoreSkipCode(code, map) {
|
|
86
|
+
for (const [withHashKey, matched] of map.entries()) code = code.replaceAll(withHashKey, matched);
|
|
87
|
+
return code;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region ../../virtual-shared/integration/src/transformers.ts
|
|
92
|
+
async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
93
|
+
if (original.includes(IGNORE_COMMENT)) return;
|
|
94
|
+
const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
|
|
95
|
+
if (!transformers.length) return;
|
|
96
|
+
const skipMap = /* @__PURE__ */ new Map();
|
|
97
|
+
let code = original;
|
|
98
|
+
let s = new magic_string.default(transformSkipCode(code, skipMap, SKIP_COMMENT_RE, "@unocss-skip-placeholder-"));
|
|
99
|
+
const maps = [];
|
|
100
|
+
for (const t of transformers) {
|
|
101
|
+
if (t.idFilter) {
|
|
102
|
+
if (!t.idFilter(id)) continue;
|
|
103
|
+
} else if (!ctx.filter(code, id)) continue;
|
|
104
|
+
await t.transform(s, id, ctx);
|
|
105
|
+
if (s.hasChanged()) {
|
|
106
|
+
code = restoreSkipCode(s.toString(), skipMap);
|
|
107
|
+
maps.push(s.generateMap({
|
|
108
|
+
hires: true,
|
|
109
|
+
source: id
|
|
110
|
+
}));
|
|
111
|
+
s = new magic_string.default(code);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (code !== original) return {
|
|
115
|
+
code,
|
|
116
|
+
map: (0, _jridgewell_remapping.default)(maps, (_, ctx$1) => {
|
|
117
|
+
ctx$1.content = code;
|
|
118
|
+
return null;
|
|
119
|
+
})
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region ../../virtual-shared/integration/src/content.ts
|
|
125
|
+
async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
126
|
+
const { content } = await ctx.getConfig();
|
|
127
|
+
const { extract, tasks, root, filter } = ctx;
|
|
128
|
+
if (content?.inline) await Promise.all(content.inline.map(async (c, idx) => {
|
|
129
|
+
if (typeof c === "function") c = await c();
|
|
130
|
+
if (typeof c === "string") c = { code: c };
|
|
131
|
+
return extract(c.code, c.id ?? `__plain_content_${idx}__`);
|
|
132
|
+
}));
|
|
133
|
+
if (content?.filesystem) {
|
|
134
|
+
const files = await (0, tinyglobby.glob)(content.filesystem, {
|
|
135
|
+
cwd: root,
|
|
136
|
+
expandDirectories: false
|
|
137
|
+
});
|
|
138
|
+
async function extractFile(file) {
|
|
139
|
+
file = (0, node_path.isAbsolute)(file) ? file : (0, node_path.resolve)(root, file);
|
|
140
|
+
const code = await node_fs_promises.default.readFile(file, "utf-8");
|
|
141
|
+
if (!filter(code, file)) return;
|
|
142
|
+
const preTransform = await applyTransformers(ctx, code, file, "pre");
|
|
143
|
+
await applyTransformers(ctx, (await applyTransformers(ctx, preTransform?.code || code, file))?.code || preTransform?.code || code, file, "post");
|
|
144
|
+
return await extract(preTransform?.code || code, file);
|
|
145
|
+
}
|
|
146
|
+
if (shouldWatch) {
|
|
147
|
+
const { watch } = await import("chokidar");
|
|
148
|
+
watch(files, {
|
|
149
|
+
ignorePermissionErrors: true,
|
|
150
|
+
ignored: ["**/{.git,node_modules}/**"],
|
|
151
|
+
cwd: root,
|
|
152
|
+
ignoreInitial: true
|
|
153
|
+
}).on("all", (type, file) => {
|
|
154
|
+
if (type === "add" || type === "change") {
|
|
155
|
+
const absolutePath = (0, node_path.resolve)(root, file);
|
|
156
|
+
tasks.push(extractFile(absolutePath));
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
await Promise.all(files.map(extractFile));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region ../../virtual-shared/integration/src/defaults.ts
|
|
166
|
+
const defaultPipelineExclude = [_unocss_core.cssIdRE];
|
|
167
|
+
const defaultPipelineInclude = [/\.(vue|svelte|[jt]sx|vine.ts|mdx?|astro|elm|php|phtml|marko|html)($|\?)/];
|
|
168
|
+
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region ../../virtual-shared/integration/src/deprecation.ts
|
|
171
|
+
function deprecationCheck(config) {}
|
|
172
|
+
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region ../../virtual-shared/integration/src/context.ts
|
|
175
|
+
function createContext(configOrPath, defaults = {}, extraConfigSources = [], resolveConfigResult = () => {}) {
|
|
176
|
+
let root = node_process.default.cwd();
|
|
177
|
+
let rawConfig = {};
|
|
178
|
+
let configFileList = [];
|
|
179
|
+
let uno;
|
|
180
|
+
const _uno = (0, _unocss_core.createGenerator)(rawConfig, defaults).then((r) => {
|
|
181
|
+
uno = r;
|
|
182
|
+
return r;
|
|
183
|
+
});
|
|
184
|
+
let rollupFilter = (0, unplugin_utils.createFilter)(defaultPipelineInclude, defaultPipelineExclude, { resolve: typeof configOrPath === "string" ? configOrPath : root });
|
|
185
|
+
const invalidations = [];
|
|
186
|
+
const reloadListeners = [];
|
|
187
|
+
const modules = new _unocss_core.BetterMap();
|
|
188
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
189
|
+
const tasks = [];
|
|
190
|
+
const affectedModules = /* @__PURE__ */ new Set();
|
|
191
|
+
const loadConfig = (0, _unocss_config.createRecoveryConfigLoader)();
|
|
192
|
+
let ready = reloadConfig();
|
|
193
|
+
async function reloadConfig() {
|
|
194
|
+
await _uno;
|
|
195
|
+
const result = await loadConfig(root, configOrPath, extraConfigSources, defaults);
|
|
196
|
+
resolveConfigResult(result);
|
|
197
|
+
/* @__PURE__ */ deprecationCheck(result.config);
|
|
198
|
+
rawConfig = result.config;
|
|
199
|
+
configFileList = result.sources;
|
|
200
|
+
await uno.setConfig(rawConfig);
|
|
201
|
+
uno.config.envMode = "dev";
|
|
202
|
+
rollupFilter = rawConfig.content?.pipeline === false ? () => false : (0, unplugin_utils.createFilter)(rawConfig.content?.pipeline?.include || defaultPipelineInclude, rawConfig.content?.pipeline?.exclude || defaultPipelineExclude, { resolve: typeof configOrPath === "string" ? configOrPath : root });
|
|
203
|
+
tokens.clear();
|
|
204
|
+
await Promise.all(modules.map((code, id) => uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens)));
|
|
205
|
+
invalidate();
|
|
206
|
+
dispatchReload();
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
async function updateRoot(newRoot) {
|
|
210
|
+
if (newRoot !== root) {
|
|
211
|
+
root = newRoot;
|
|
212
|
+
ready = reloadConfig();
|
|
213
|
+
}
|
|
214
|
+
return await ready;
|
|
215
|
+
}
|
|
216
|
+
function invalidate() {
|
|
217
|
+
invalidations.forEach((cb) => cb());
|
|
218
|
+
}
|
|
219
|
+
function dispatchReload() {
|
|
220
|
+
reloadListeners.forEach((cb) => cb());
|
|
221
|
+
}
|
|
222
|
+
async function extract(code, id) {
|
|
223
|
+
const uno$1 = await _uno;
|
|
224
|
+
if (id) modules.set(id, code);
|
|
225
|
+
const len = tokens.size;
|
|
226
|
+
await uno$1.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
|
|
227
|
+
if (tokens.size > len) invalidate();
|
|
228
|
+
}
|
|
229
|
+
function filter(code, id) {
|
|
230
|
+
if (code.includes(IGNORE_COMMENT)) return false;
|
|
231
|
+
return code.includes(INCLUDE_COMMENT) || code.includes(CSS_PLACEHOLDER) || rollupFilter(id.replace(/\?v=\w+$/, ""));
|
|
232
|
+
}
|
|
233
|
+
async function getConfig() {
|
|
234
|
+
await ready;
|
|
235
|
+
return rawConfig;
|
|
236
|
+
}
|
|
237
|
+
async function flushTasks() {
|
|
238
|
+
const _tasks = [...tasks];
|
|
239
|
+
await Promise.all(_tasks);
|
|
240
|
+
if (tasks[0] === _tasks[0]) tasks.splice(0, _tasks.length);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Get regexes to match virtual module ids
|
|
244
|
+
*/
|
|
245
|
+
const vmpCache = /* @__PURE__ */ new Map();
|
|
246
|
+
async function getVMPRegexes() {
|
|
247
|
+
const prefix = (await getConfig()).virtualModulePrefix || "__uno";
|
|
248
|
+
if (vmpCache.has(prefix)) return vmpCache.get(prefix);
|
|
249
|
+
const regexes = {
|
|
250
|
+
prefix,
|
|
251
|
+
RESOLVED_ID_WITH_QUERY_RE: /* @__PURE__ */ new RegExp(`[/\\\\]${prefix}(_.*?)?\\.css(\\?.*)?$`),
|
|
252
|
+
RESOLVED_ID_RE: /* @__PURE__ */ new RegExp(`[/\\\\]${prefix}(?:_(.*?))?\.css$`)
|
|
253
|
+
};
|
|
254
|
+
vmpCache.set(prefix, regexes);
|
|
255
|
+
return regexes;
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
get ready() {
|
|
259
|
+
return ready;
|
|
260
|
+
},
|
|
261
|
+
tokens,
|
|
262
|
+
modules,
|
|
263
|
+
affectedModules,
|
|
264
|
+
tasks,
|
|
265
|
+
flushTasks,
|
|
266
|
+
invalidate,
|
|
267
|
+
onInvalidate(fn) {
|
|
268
|
+
invalidations.push(fn);
|
|
269
|
+
},
|
|
270
|
+
filter,
|
|
271
|
+
reloadConfig,
|
|
272
|
+
onReload(fn) {
|
|
273
|
+
reloadListeners.push(fn);
|
|
274
|
+
},
|
|
275
|
+
get uno() {
|
|
276
|
+
if (!uno) throw new Error("Run `await context.ready` before accessing `context.uno`");
|
|
277
|
+
return uno;
|
|
278
|
+
},
|
|
279
|
+
extract,
|
|
280
|
+
getConfig,
|
|
281
|
+
get root() {
|
|
282
|
+
return root;
|
|
283
|
+
},
|
|
284
|
+
updateRoot,
|
|
285
|
+
getConfigFileList: () => configFileList,
|
|
286
|
+
getVMPRegexes
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
//#endregion
|
|
291
|
+
//#region ../../virtual-shared/integration/src/hash.ts
|
|
292
|
+
const hash = node_crypto.default.hash ?? ((algorithm, data, outputEncoding) => node_crypto.default.createHash(algorithm).update(data).digest(outputEncoding));
|
|
293
|
+
function getHash(input, length = 8) {
|
|
294
|
+
return hash("sha256", input, "hex").substring(0, length);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region ../../virtual-shared/integration/src/layers.ts
|
|
299
|
+
async function resolveId(ctx, id, importer) {
|
|
300
|
+
const { RESOLVED_ID_WITH_QUERY_RE, prefix } = await ctx.getVMPRegexes();
|
|
301
|
+
if (id.match(RESOLVED_ID_WITH_QUERY_RE)) return id;
|
|
302
|
+
for (const alias of VIRTUAL_ENTRY_ALIAS) {
|
|
303
|
+
const match = id.match(alias);
|
|
304
|
+
if (match) {
|
|
305
|
+
let virtual = match[1] ? `${prefix}_${match[1]}.css` : `${prefix}.css`;
|
|
306
|
+
virtual += match[2] || "";
|
|
307
|
+
if (importer) virtual = (0, pathe.resolve)(importer, "..", virtual);
|
|
308
|
+
else virtual = `/${virtual}`;
|
|
309
|
+
return virtual;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
async function resolveLayer(ctx, id) {
|
|
314
|
+
const { RESOLVED_ID_RE } = await ctx.getVMPRegexes();
|
|
315
|
+
const match = id.match(RESOLVED_ID_RE);
|
|
316
|
+
if (match) return match[1] || LAYER_MARK_ALL;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* 1 - layer
|
|
320
|
+
* 2 - escape-view
|
|
321
|
+
* 111 222
|
|
322
|
+
*/
|
|
323
|
+
const LAYER_PLACEHOLDER_RE = /#--unocss--\s*\{\s*layer\s*:\s*(.+?)\s*(?:;\s*escape-view\s*:\s*(.+?)\s*)?;?\s*\}/g;
|
|
324
|
+
function getLayerPlaceholder(layer) {
|
|
325
|
+
return `#--unocss--{layer:${layer};escape-view:\\"\\'\\\`\\\\}`;
|
|
326
|
+
}
|
|
327
|
+
function getCssEscaperForJsContent(view) {
|
|
328
|
+
if (!view) return (css) => css;
|
|
329
|
+
const prefix = {};
|
|
330
|
+
view.trim().replace(/(\\*)\\(["'`\\])/g, (_, bs, char) => {
|
|
331
|
+
prefix[char] = bs.replace(/\\\\/g, "\\");
|
|
332
|
+
return "";
|
|
333
|
+
});
|
|
334
|
+
return (css) => css.replace(/["'`\\]/g, (v) => {
|
|
335
|
+
return (prefix[v] || "") + v;
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
const HASH_PLACEHOLDER_RE = /#--unocss-hash--\s*\{\s*content\s*:\s*\\*"([^\\"]+)\\*";?\s*\}/g;
|
|
339
|
+
function getHashPlaceholder(hash$2) {
|
|
340
|
+
return `#--unocss-hash--{content:"${hash$2}"}`;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region src/unplugin.ts
|
|
345
|
+
const PLUGIN_NAME = "unocss:webpack";
|
|
346
|
+
const UPDATE_DEBOUNCE = 10;
|
|
347
|
+
function unplugin$1(configOrPath, defaults) {
|
|
348
|
+
return (0, unplugin.createUnplugin)(() => {
|
|
349
|
+
const ctx = createContext(configOrPath, {
|
|
350
|
+
envMode: node_process.default.env.NODE_ENV === "development" ? "dev" : "build",
|
|
351
|
+
...defaults
|
|
352
|
+
});
|
|
353
|
+
const { tokens, filter, extract, onInvalidate, tasks, flushTasks } = ctx;
|
|
354
|
+
let timer;
|
|
355
|
+
onInvalidate(() => {
|
|
356
|
+
clearTimeout(timer);
|
|
357
|
+
timer = setTimeout(updateModules, UPDATE_DEBOUNCE);
|
|
358
|
+
});
|
|
359
|
+
tasks.push(setupContentExtractor(ctx, typeof configOrPath === "object" && configOrPath?.watch));
|
|
360
|
+
const entries = /* @__PURE__ */ new Set();
|
|
361
|
+
const hashes = /* @__PURE__ */ new Map();
|
|
362
|
+
const plugin = {
|
|
363
|
+
name: "unocss:webpack",
|
|
364
|
+
enforce: "pre",
|
|
365
|
+
async transform(code, id) {
|
|
366
|
+
const { RESOLVED_ID_RE } = await ctx.getVMPRegexes();
|
|
367
|
+
if (RESOLVED_ID_RE.test(id) || !filter("", id) || id.endsWith(".html")) return;
|
|
368
|
+
const result = await applyTransformers(ctx, code, id, "pre");
|
|
369
|
+
if (isCssId(id)) return result;
|
|
370
|
+
if (result == null) tasks.push(extract(code, id));
|
|
371
|
+
else tasks.push(extract(result.code, id));
|
|
372
|
+
return result;
|
|
373
|
+
},
|
|
374
|
+
async resolveId(id) {
|
|
375
|
+
const entry = await resolveId(ctx, id);
|
|
376
|
+
if (entry === id) return;
|
|
377
|
+
if (entry) {
|
|
378
|
+
let query = "";
|
|
379
|
+
const queryIndex = id.indexOf("?");
|
|
380
|
+
if (queryIndex >= 0) query = id.slice(queryIndex);
|
|
381
|
+
entries.add(entry);
|
|
382
|
+
return entry + query;
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
async load(id) {
|
|
386
|
+
const layer = await getLayer(ctx, id);
|
|
387
|
+
if (!layer) return;
|
|
388
|
+
const hash$2 = hashes.get(id);
|
|
389
|
+
return (hash$2 ? getHashPlaceholder(hash$2) : "") + getLayerPlaceholder(layer);
|
|
390
|
+
},
|
|
391
|
+
webpack(compiler) {
|
|
392
|
+
compiler.hooks.beforeCompile.tapPromise(PLUGIN_NAME, async () => {
|
|
393
|
+
await ctx.ready;
|
|
394
|
+
const nonPreTransformers = ctx.uno.config.transformers?.filter((i) => i.enforce !== "pre");
|
|
395
|
+
if (nonPreTransformers?.length) console.warn("[unocss] webpack integration only supports \"pre\" enforce transformers currently.the following transformers will be ignored\n" + nonPreTransformers.map((i) => ` - ${i.name}`).join("\n"));
|
|
396
|
+
});
|
|
397
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
398
|
+
(compilation.hooks.processAssets || compilation.hooks.optimizeAssets).tapPromise(PLUGIN_NAME, async () => {
|
|
399
|
+
await ctx.ready;
|
|
400
|
+
const files = Object.keys(compilation.assets);
|
|
401
|
+
await flushTasks();
|
|
402
|
+
const result = await ctx.uno.generate(tokens, { minify: true });
|
|
403
|
+
const resolvedLayers = (await Promise.all(Array.from(entries).map((i) => resolveLayer(ctx, i)))).filter((i) => !!i);
|
|
404
|
+
for (const file of files) {
|
|
405
|
+
if (file === "*") return;
|
|
406
|
+
let code = compilation.assets[file].source().toString();
|
|
407
|
+
let escapeCss;
|
|
408
|
+
let replaced = false;
|
|
409
|
+
code = code.replace(HASH_PLACEHOLDER_RE, "");
|
|
410
|
+
code = code.replace(LAYER_PLACEHOLDER_RE, (_, layer, escapeView) => {
|
|
411
|
+
replaced = true;
|
|
412
|
+
const css = layer.trim() === LAYER_MARK_ALL ? result.getLayers(void 0, resolvedLayers) : result.getLayer(layer) || "";
|
|
413
|
+
escapeCss = escapeCss ?? getCssEscaperForJsContent(escapeView.trim());
|
|
414
|
+
return escapeCss(css);
|
|
415
|
+
});
|
|
416
|
+
if (replaced) compilation.assets[file] = new webpack_sources.default.SourceMapSource(code, file, compilation.assets[file].map());
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
},
|
|
421
|
+
get rspack() {
|
|
422
|
+
return this.webpack;
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
let lastTokenSize = tokens.size;
|
|
426
|
+
async function updateModules() {
|
|
427
|
+
if (!plugin.__vfsModules) return;
|
|
428
|
+
await flushTasks();
|
|
429
|
+
const result = await ctx.uno.generate(tokens);
|
|
430
|
+
if (lastTokenSize === tokens.size) return;
|
|
431
|
+
lastTokenSize = tokens.size;
|
|
432
|
+
let virtualModules;
|
|
433
|
+
if (plugin.__vfsModules instanceof Map) virtualModules = Array.from(plugin.__vfsModules.keys());
|
|
434
|
+
else virtualModules = Array.from(plugin.__vfsModules);
|
|
435
|
+
const resolvedLayers = (await Promise.all(Array.from(entries).map((i) => resolveLayer(ctx, i)))).filter((i) => !!i);
|
|
436
|
+
for (const id of virtualModules) {
|
|
437
|
+
let path = decodeURIComponent(id.startsWith(plugin.__virtualModulePrefix) ? id.slice(plugin.__virtualModulePrefix.length) : id);
|
|
438
|
+
path = normalizeAbsolutePath(path);
|
|
439
|
+
const layer = await resolveLayer(ctx, path);
|
|
440
|
+
if (!layer) continue;
|
|
441
|
+
const code = layer === LAYER_MARK_ALL ? result.getLayers(void 0, resolvedLayers) : result.getLayer(layer) || "";
|
|
442
|
+
const hash$2 = getHash(code);
|
|
443
|
+
hashes.set(path, hash$2);
|
|
444
|
+
plugin.__vfs.writeModule(id, code);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return plugin;
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
async function getLayer(ctx, id) {
|
|
451
|
+
let layer = await resolveLayer(ctx, getPath(id));
|
|
452
|
+
if (!layer) {
|
|
453
|
+
const entry = await resolveId(ctx, id);
|
|
454
|
+
if (entry) layer = await resolveLayer(ctx, entry);
|
|
455
|
+
}
|
|
456
|
+
return layer;
|
|
457
|
+
}
|
|
458
|
+
function normalizeAbsolutePath(path) {
|
|
459
|
+
if ((0, node_path.isAbsolute)(path)) return (0, node_path.normalize)(path);
|
|
460
|
+
else return path;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
//#endregion
|
|
464
|
+
Object.defineProperty(exports, 'unplugin', {
|
|
465
|
+
enumerable: true,
|
|
466
|
+
get: function () {
|
|
467
|
+
return unplugin$1;
|
|
468
|
+
}
|
|
469
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/webpack",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "66.5.
|
|
4
|
+
"version": "66.5.11",
|
|
5
5
|
"description": "The Webpack plugin for UnoCSS",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -44,10 +44,11 @@
|
|
|
44
44
|
},
|
|
45
45
|
"main": "./dist/index.cjs",
|
|
46
46
|
"module": "./dist/index.mjs",
|
|
47
|
-
"types": "./dist/index.d.
|
|
47
|
+
"types": "./dist/index.d.cts",
|
|
48
48
|
"typesVersions": {
|
|
49
49
|
"*": {
|
|
50
50
|
"*": [
|
|
51
|
+
"./dist/*.d.cts",
|
|
51
52
|
"./dist/*",
|
|
52
53
|
"./*"
|
|
53
54
|
]
|
|
@@ -61,24 +62,23 @@
|
|
|
61
62
|
},
|
|
62
63
|
"dependencies": {
|
|
63
64
|
"@jridgewell/remapping": "^2.3.5",
|
|
64
|
-
"chokidar": "^
|
|
65
|
+
"chokidar": "^5.0.0",
|
|
65
66
|
"magic-string": "^0.30.21",
|
|
66
67
|
"pathe": "^2.0.3",
|
|
67
68
|
"tinyglobby": "^0.2.15",
|
|
68
|
-
"unplugin": "^2.3.
|
|
69
|
+
"unplugin": "^2.3.11",
|
|
69
70
|
"unplugin-utils": "^0.3.1",
|
|
70
71
|
"webpack-sources": "^3.3.3",
|
|
71
|
-
"@unocss/config": "66.5.
|
|
72
|
-
"@unocss/core": "66.5.
|
|
72
|
+
"@unocss/config": "66.5.11",
|
|
73
|
+
"@unocss/core": "66.5.11"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
76
|
"@types/webpack": "^5.28.5",
|
|
76
77
|
"@types/webpack-sources": "^3.2.3",
|
|
77
|
-
"webpack": "^5.
|
|
78
|
+
"webpack": "^5.104.1"
|
|
78
79
|
},
|
|
79
80
|
"scripts": {
|
|
80
|
-
"build": "
|
|
81
|
-
"
|
|
82
|
-
"test:attw": "attw --pack"
|
|
81
|
+
"build": "tsdown --config-loader unrun",
|
|
82
|
+
"dev": "tsdown --config-loader unrun --watch"
|
|
83
83
|
}
|
|
84
84
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as webpack from 'webpack';
|
|
2
|
-
import { UserConfig, UserConfigDefaults } from '@unocss/core';
|
|
3
|
-
|
|
4
|
-
interface WebpackPluginOptions<Theme extends object = object> extends UserConfig<Theme> {
|
|
5
|
-
/**
|
|
6
|
-
* Manually enable watch mode
|
|
7
|
-
*
|
|
8
|
-
* @default false
|
|
9
|
-
*/
|
|
10
|
-
watch?: boolean;
|
|
11
|
-
}
|
|
12
|
-
declare function WebpackPlugin<Theme extends object>(configOrPath?: WebpackPluginOptions<Theme> | string, defaults?: UserConfigDefaults): webpack.WebpackPluginInstance;
|
|
13
|
-
|
|
14
|
-
export = WebpackPlugin;
|
|
15
|
-
export type { WebpackPluginOptions };
|
package/dist/rspack.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { UserConfigDefaults } from '@unocss/core';
|
|
2
|
-
import { WebpackPluginOptions } from './index.js';
|
|
3
|
-
import 'webpack';
|
|
4
|
-
|
|
5
|
-
declare function UnoCSSRspackPlugin<Theme extends object>(configOrPath?: WebpackPluginOptions<Theme> | string, defaults?: UserConfigDefaults): RspackPluginInstance;
|
|
6
|
-
|
|
7
|
-
export { UnoCSSRspackPlugin };
|