@unocss/webpack 0.62.2 → 0.62.4
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.cjs +120 -120
- package/dist/index.mjs +119 -119
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const process$1 = require('node:process');
|
|
6
5
|
const node_path = require('node:path');
|
|
6
|
+
const process$1 = require('node:process');
|
|
7
7
|
const unplugin = require('unplugin');
|
|
8
8
|
const WebpackSources = require('webpack-sources');
|
|
9
|
-
const pluginutils = require('@rollup/pluginutils');
|
|
10
|
-
const config = require('@unocss/config');
|
|
11
|
-
const core = require('@unocss/core');
|
|
12
9
|
const fs = require('node:fs/promises');
|
|
13
10
|
const tinyglobby = require('tinyglobby');
|
|
14
|
-
const MagicString = require('magic-string');
|
|
15
11
|
const remapping = require('@ampproject/remapping');
|
|
12
|
+
const MagicString = require('magic-string');
|
|
13
|
+
const core = require('@unocss/core');
|
|
14
|
+
const pluginutils = require('@rollup/pluginutils');
|
|
15
|
+
const config = require('@unocss/config');
|
|
16
16
|
const node_crypto = require('node:crypto');
|
|
17
17
|
|
|
18
18
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
@@ -20,8 +20,8 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
20
20
|
const process__default = /*#__PURE__*/_interopDefaultCompat(process$1);
|
|
21
21
|
const WebpackSources__default = /*#__PURE__*/_interopDefaultCompat(WebpackSources);
|
|
22
22
|
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
23
|
-
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
|
24
23
|
const remapping__default = /*#__PURE__*/_interopDefaultCompat(remapping);
|
|
24
|
+
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
|
25
25
|
|
|
26
26
|
const INCLUDE_COMMENT = "@unocss-include";
|
|
27
27
|
const IGNORE_COMMENT = "@unocss-ignore";
|
|
@@ -30,6 +30,120 @@ const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
|
30
30
|
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
31
31
|
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");
|
|
32
32
|
|
|
33
|
+
function getPath(id) {
|
|
34
|
+
return id.replace(/\?.*$/, "");
|
|
35
|
+
}
|
|
36
|
+
function isCssId(id) {
|
|
37
|
+
return core.cssIdRE.test(id);
|
|
38
|
+
}
|
|
39
|
+
function hash(str) {
|
|
40
|
+
let i;
|
|
41
|
+
let l;
|
|
42
|
+
let hval = 2166136261;
|
|
43
|
+
for (i = 0, l = str.length; i < l; i++) {
|
|
44
|
+
hval ^= str.charCodeAt(i);
|
|
45
|
+
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
46
|
+
}
|
|
47
|
+
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
48
|
+
}
|
|
49
|
+
function transformSkipCode(code, map, SKIP_RULES_RE, keyFlag) {
|
|
50
|
+
for (const item of Array.from(code.matchAll(SKIP_RULES_RE))) {
|
|
51
|
+
if (item != null) {
|
|
52
|
+
const matched = item[0];
|
|
53
|
+
const withHashKey = `${keyFlag}${hash(matched)}`;
|
|
54
|
+
map.set(withHashKey, matched);
|
|
55
|
+
code = code.replace(matched, withHashKey);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return code;
|
|
59
|
+
}
|
|
60
|
+
function restoreSkipCode(code, map) {
|
|
61
|
+
for (const [withHashKey, matched] of map.entries())
|
|
62
|
+
code = code.replaceAll(withHashKey, matched);
|
|
63
|
+
return code;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
67
|
+
if (original.includes(IGNORE_COMMENT))
|
|
68
|
+
return;
|
|
69
|
+
const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
|
|
70
|
+
if (!transformers.length)
|
|
71
|
+
return;
|
|
72
|
+
const skipMap = /* @__PURE__ */ new Map();
|
|
73
|
+
let code = original;
|
|
74
|
+
let s = new MagicString__default(transformSkipCode(code, skipMap, SKIP_COMMENT_RE, "@unocss-skip-placeholder-"));
|
|
75
|
+
const maps = [];
|
|
76
|
+
for (const t of transformers) {
|
|
77
|
+
if (t.idFilter) {
|
|
78
|
+
if (!t.idFilter(id))
|
|
79
|
+
continue;
|
|
80
|
+
} else if (!ctx.filter(code, id)) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
await t.transform(s, id, ctx);
|
|
84
|
+
if (s.hasChanged()) {
|
|
85
|
+
code = restoreSkipCode(s.toString(), skipMap);
|
|
86
|
+
maps.push(s.generateMap({ hires: true, source: id }));
|
|
87
|
+
s = new MagicString__default(code);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (code !== original) {
|
|
91
|
+
return {
|
|
92
|
+
code,
|
|
93
|
+
map: remapping__default(maps, (_, ctx2) => {
|
|
94
|
+
ctx2.content = code;
|
|
95
|
+
return null;
|
|
96
|
+
})
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
102
|
+
const { content } = await ctx.getConfig();
|
|
103
|
+
const { extract, tasks, root, filter } = ctx;
|
|
104
|
+
if (content?.inline) {
|
|
105
|
+
await Promise.all(
|
|
106
|
+
content.inline.map(async (c, idx) => {
|
|
107
|
+
if (typeof c === "function")
|
|
108
|
+
c = await c();
|
|
109
|
+
if (typeof c === "string")
|
|
110
|
+
c = { code: c };
|
|
111
|
+
return extract(c.code, c.id ?? `__plain_content_${idx}__`);
|
|
112
|
+
})
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
if (content?.filesystem) {
|
|
116
|
+
const files = await tinyglobby.glob(content.filesystem, { cwd: root, expandDirectories: false });
|
|
117
|
+
async function extractFile(file) {
|
|
118
|
+
file = node_path.isAbsolute(file) ? file : node_path.resolve(root, file);
|
|
119
|
+
const code = await fs__default.readFile(file, "utf-8");
|
|
120
|
+
if (!filter(code, file))
|
|
121
|
+
return;
|
|
122
|
+
const preTransform = await applyTransformers(ctx, code, file, "pre");
|
|
123
|
+
const defaultTransform = await applyTransformers(ctx, preTransform?.code || code, file);
|
|
124
|
+
await applyTransformers(ctx, defaultTransform?.code || preTransform?.code || code, file, "post");
|
|
125
|
+
return await extract(preTransform?.code || code, file);
|
|
126
|
+
}
|
|
127
|
+
if (shouldWatch) {
|
|
128
|
+
const { watch } = await import('chokidar');
|
|
129
|
+
const ignored = ["**/{.git,node_modules}/**"];
|
|
130
|
+
const watcher = watch(files, {
|
|
131
|
+
ignorePermissionErrors: true,
|
|
132
|
+
ignored,
|
|
133
|
+
cwd: root,
|
|
134
|
+
ignoreInitial: true
|
|
135
|
+
});
|
|
136
|
+
watcher.on("all", (type, file) => {
|
|
137
|
+
if (type === "add" || type === "change") {
|
|
138
|
+
const absolutePath = node_path.resolve(root, file);
|
|
139
|
+
tasks.push(extractFile(absolutePath));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
await Promise.all(files.map(extractFile));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
33
147
|
const defaultPipelineExclude = [core.cssIdRE];
|
|
34
148
|
const defaultPipelineInclude = [/\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/];
|
|
35
149
|
|
|
@@ -163,120 +277,6 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
163
277
|
};
|
|
164
278
|
}
|
|
165
279
|
|
|
166
|
-
function getPath(id) {
|
|
167
|
-
return id.replace(/\?.*$/, "");
|
|
168
|
-
}
|
|
169
|
-
function isCssId(id) {
|
|
170
|
-
return core.cssIdRE.test(id);
|
|
171
|
-
}
|
|
172
|
-
function hash(str) {
|
|
173
|
-
let i;
|
|
174
|
-
let l;
|
|
175
|
-
let hval = 2166136261;
|
|
176
|
-
for (i = 0, l = str.length; i < l; i++) {
|
|
177
|
-
hval ^= str.charCodeAt(i);
|
|
178
|
-
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
179
|
-
}
|
|
180
|
-
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
181
|
-
}
|
|
182
|
-
function transformSkipCode(code, map, SKIP_RULES_RE, keyFlag) {
|
|
183
|
-
for (const item of Array.from(code.matchAll(SKIP_RULES_RE))) {
|
|
184
|
-
if (item != null) {
|
|
185
|
-
const matched = item[0];
|
|
186
|
-
const withHashKey = `${keyFlag}${hash(matched)}`;
|
|
187
|
-
map.set(withHashKey, matched);
|
|
188
|
-
code = code.replace(matched, withHashKey);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return code;
|
|
192
|
-
}
|
|
193
|
-
function restoreSkipCode(code, map) {
|
|
194
|
-
for (const [withHashKey, matched] of map.entries())
|
|
195
|
-
code = code.replaceAll(withHashKey, matched);
|
|
196
|
-
return code;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
200
|
-
if (original.includes(IGNORE_COMMENT))
|
|
201
|
-
return;
|
|
202
|
-
const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
|
|
203
|
-
if (!transformers.length)
|
|
204
|
-
return;
|
|
205
|
-
const skipMap = /* @__PURE__ */ new Map();
|
|
206
|
-
let code = original;
|
|
207
|
-
let s = new MagicString__default(transformSkipCode(code, skipMap, SKIP_COMMENT_RE, "@unocss-skip-placeholder-"));
|
|
208
|
-
const maps = [];
|
|
209
|
-
for (const t of transformers) {
|
|
210
|
-
if (t.idFilter) {
|
|
211
|
-
if (!t.idFilter(id))
|
|
212
|
-
continue;
|
|
213
|
-
} else if (!ctx.filter(code, id)) {
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
await t.transform(s, id, ctx);
|
|
217
|
-
if (s.hasChanged()) {
|
|
218
|
-
code = restoreSkipCode(s.toString(), skipMap);
|
|
219
|
-
maps.push(s.generateMap({ hires: true, source: id }));
|
|
220
|
-
s = new MagicString__default(code);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if (code !== original) {
|
|
224
|
-
return {
|
|
225
|
-
code,
|
|
226
|
-
map: remapping__default(maps, (_, ctx2) => {
|
|
227
|
-
ctx2.content = code;
|
|
228
|
-
return null;
|
|
229
|
-
})
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
235
|
-
const { content } = await ctx.getConfig();
|
|
236
|
-
const { extract, tasks, root, filter } = ctx;
|
|
237
|
-
if (content?.inline) {
|
|
238
|
-
await Promise.all(
|
|
239
|
-
content.inline.map(async (c, idx) => {
|
|
240
|
-
if (typeof c === "function")
|
|
241
|
-
c = await c();
|
|
242
|
-
if (typeof c === "string")
|
|
243
|
-
c = { code: c };
|
|
244
|
-
return extract(c.code, c.id ?? `__plain_content_${idx}__`);
|
|
245
|
-
})
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
if (content?.filesystem) {
|
|
249
|
-
const files = await tinyglobby.glob(content.filesystem, { cwd: root, expandDirectories: false });
|
|
250
|
-
async function extractFile(file) {
|
|
251
|
-
file = node_path.isAbsolute(file) ? file : node_path.resolve(root, file);
|
|
252
|
-
const code = await fs__default.readFile(file, "utf-8");
|
|
253
|
-
if (!filter(code, file))
|
|
254
|
-
return;
|
|
255
|
-
const preTransform = await applyTransformers(ctx, code, file, "pre");
|
|
256
|
-
const defaultTransform = await applyTransformers(ctx, preTransform?.code || code, file);
|
|
257
|
-
await applyTransformers(ctx, defaultTransform?.code || preTransform?.code || code, file, "post");
|
|
258
|
-
return await extract(preTransform?.code || code, file);
|
|
259
|
-
}
|
|
260
|
-
if (shouldWatch) {
|
|
261
|
-
const { watch } = await import('chokidar');
|
|
262
|
-
const ignored = ["**/{.git,node_modules}/**"];
|
|
263
|
-
const watcher = watch(files, {
|
|
264
|
-
ignorePermissionErrors: true,
|
|
265
|
-
ignored,
|
|
266
|
-
cwd: root,
|
|
267
|
-
ignoreInitial: true
|
|
268
|
-
});
|
|
269
|
-
watcher.on("all", (type, file) => {
|
|
270
|
-
if (type === "add" || type === "change") {
|
|
271
|
-
const absolutePath = node_path.resolve(root, file);
|
|
272
|
-
tasks.push(extractFile(absolutePath));
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
await Promise.all(files.map(extractFile));
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
280
|
function getHash(input, length = 8) {
|
|
281
281
|
return node_crypto.createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
282
282
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import process$1 from 'node:process';
|
|
2
1
|
import { resolve, isAbsolute, normalize } from 'node:path';
|
|
2
|
+
import process$1 from 'node:process';
|
|
3
3
|
import { createUnplugin } from 'unplugin';
|
|
4
4
|
import WebpackSources from 'webpack-sources';
|
|
5
|
-
import { createFilter } from '@rollup/pluginutils';
|
|
6
|
-
import { createRecoveryConfigLoader } from '@unocss/config';
|
|
7
|
-
import { cssIdRE, createGenerator, BetterMap } from '@unocss/core';
|
|
8
5
|
import fs from 'node:fs/promises';
|
|
9
6
|
import { glob } from 'tinyglobby';
|
|
10
|
-
import MagicString from 'magic-string';
|
|
11
7
|
import remapping from '@ampproject/remapping';
|
|
8
|
+
import MagicString from 'magic-string';
|
|
9
|
+
import { cssIdRE, createGenerator, BetterMap } from '@unocss/core';
|
|
10
|
+
import { createFilter } from '@rollup/pluginutils';
|
|
11
|
+
import { createRecoveryConfigLoader } from '@unocss/config';
|
|
12
12
|
import { createHash } from 'node:crypto';
|
|
13
13
|
|
|
14
14
|
const INCLUDE_COMMENT = "@unocss-include";
|
|
@@ -18,6 +18,120 @@ const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
|
18
18
|
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
19
19
|
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");
|
|
20
20
|
|
|
21
|
+
function getPath(id) {
|
|
22
|
+
return id.replace(/\?.*$/, "");
|
|
23
|
+
}
|
|
24
|
+
function isCssId(id) {
|
|
25
|
+
return cssIdRE.test(id);
|
|
26
|
+
}
|
|
27
|
+
function hash(str) {
|
|
28
|
+
let i;
|
|
29
|
+
let l;
|
|
30
|
+
let hval = 2166136261;
|
|
31
|
+
for (i = 0, l = str.length; i < l; i++) {
|
|
32
|
+
hval ^= str.charCodeAt(i);
|
|
33
|
+
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
34
|
+
}
|
|
35
|
+
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
36
|
+
}
|
|
37
|
+
function transformSkipCode(code, map, SKIP_RULES_RE, keyFlag) {
|
|
38
|
+
for (const item of Array.from(code.matchAll(SKIP_RULES_RE))) {
|
|
39
|
+
if (item != null) {
|
|
40
|
+
const matched = item[0];
|
|
41
|
+
const withHashKey = `${keyFlag}${hash(matched)}`;
|
|
42
|
+
map.set(withHashKey, matched);
|
|
43
|
+
code = code.replace(matched, withHashKey);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return code;
|
|
47
|
+
}
|
|
48
|
+
function restoreSkipCode(code, map) {
|
|
49
|
+
for (const [withHashKey, matched] of map.entries())
|
|
50
|
+
code = code.replaceAll(withHashKey, matched);
|
|
51
|
+
return code;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
55
|
+
if (original.includes(IGNORE_COMMENT))
|
|
56
|
+
return;
|
|
57
|
+
const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
|
|
58
|
+
if (!transformers.length)
|
|
59
|
+
return;
|
|
60
|
+
const skipMap = /* @__PURE__ */ new Map();
|
|
61
|
+
let code = original;
|
|
62
|
+
let s = new MagicString(transformSkipCode(code, skipMap, SKIP_COMMENT_RE, "@unocss-skip-placeholder-"));
|
|
63
|
+
const maps = [];
|
|
64
|
+
for (const t of transformers) {
|
|
65
|
+
if (t.idFilter) {
|
|
66
|
+
if (!t.idFilter(id))
|
|
67
|
+
continue;
|
|
68
|
+
} else if (!ctx.filter(code, id)) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
await t.transform(s, id, ctx);
|
|
72
|
+
if (s.hasChanged()) {
|
|
73
|
+
code = restoreSkipCode(s.toString(), skipMap);
|
|
74
|
+
maps.push(s.generateMap({ hires: true, source: id }));
|
|
75
|
+
s = new MagicString(code);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (code !== original) {
|
|
79
|
+
return {
|
|
80
|
+
code,
|
|
81
|
+
map: remapping(maps, (_, ctx2) => {
|
|
82
|
+
ctx2.content = code;
|
|
83
|
+
return null;
|
|
84
|
+
})
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
90
|
+
const { content } = await ctx.getConfig();
|
|
91
|
+
const { extract, tasks, root, filter } = ctx;
|
|
92
|
+
if (content?.inline) {
|
|
93
|
+
await Promise.all(
|
|
94
|
+
content.inline.map(async (c, idx) => {
|
|
95
|
+
if (typeof c === "function")
|
|
96
|
+
c = await c();
|
|
97
|
+
if (typeof c === "string")
|
|
98
|
+
c = { code: c };
|
|
99
|
+
return extract(c.code, c.id ?? `__plain_content_${idx}__`);
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if (content?.filesystem) {
|
|
104
|
+
const files = await glob(content.filesystem, { cwd: root, expandDirectories: false });
|
|
105
|
+
async function extractFile(file) {
|
|
106
|
+
file = isAbsolute(file) ? file : resolve(root, file);
|
|
107
|
+
const code = await fs.readFile(file, "utf-8");
|
|
108
|
+
if (!filter(code, file))
|
|
109
|
+
return;
|
|
110
|
+
const preTransform = await applyTransformers(ctx, code, file, "pre");
|
|
111
|
+
const defaultTransform = await applyTransformers(ctx, preTransform?.code || code, file);
|
|
112
|
+
await applyTransformers(ctx, defaultTransform?.code || preTransform?.code || code, file, "post");
|
|
113
|
+
return await extract(preTransform?.code || code, file);
|
|
114
|
+
}
|
|
115
|
+
if (shouldWatch) {
|
|
116
|
+
const { watch } = await import('chokidar');
|
|
117
|
+
const ignored = ["**/{.git,node_modules}/**"];
|
|
118
|
+
const watcher = watch(files, {
|
|
119
|
+
ignorePermissionErrors: true,
|
|
120
|
+
ignored,
|
|
121
|
+
cwd: root,
|
|
122
|
+
ignoreInitial: true
|
|
123
|
+
});
|
|
124
|
+
watcher.on("all", (type, file) => {
|
|
125
|
+
if (type === "add" || type === "change") {
|
|
126
|
+
const absolutePath = resolve(root, file);
|
|
127
|
+
tasks.push(extractFile(absolutePath));
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
await Promise.all(files.map(extractFile));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
21
135
|
const defaultPipelineExclude = [cssIdRE];
|
|
22
136
|
const defaultPipelineInclude = [/\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/];
|
|
23
137
|
|
|
@@ -151,120 +265,6 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
151
265
|
};
|
|
152
266
|
}
|
|
153
267
|
|
|
154
|
-
function getPath(id) {
|
|
155
|
-
return id.replace(/\?.*$/, "");
|
|
156
|
-
}
|
|
157
|
-
function isCssId(id) {
|
|
158
|
-
return cssIdRE.test(id);
|
|
159
|
-
}
|
|
160
|
-
function hash(str) {
|
|
161
|
-
let i;
|
|
162
|
-
let l;
|
|
163
|
-
let hval = 2166136261;
|
|
164
|
-
for (i = 0, l = str.length; i < l; i++) {
|
|
165
|
-
hval ^= str.charCodeAt(i);
|
|
166
|
-
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
167
|
-
}
|
|
168
|
-
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
169
|
-
}
|
|
170
|
-
function transformSkipCode(code, map, SKIP_RULES_RE, keyFlag) {
|
|
171
|
-
for (const item of Array.from(code.matchAll(SKIP_RULES_RE))) {
|
|
172
|
-
if (item != null) {
|
|
173
|
-
const matched = item[0];
|
|
174
|
-
const withHashKey = `${keyFlag}${hash(matched)}`;
|
|
175
|
-
map.set(withHashKey, matched);
|
|
176
|
-
code = code.replace(matched, withHashKey);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return code;
|
|
180
|
-
}
|
|
181
|
-
function restoreSkipCode(code, map) {
|
|
182
|
-
for (const [withHashKey, matched] of map.entries())
|
|
183
|
-
code = code.replaceAll(withHashKey, matched);
|
|
184
|
-
return code;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
188
|
-
if (original.includes(IGNORE_COMMENT))
|
|
189
|
-
return;
|
|
190
|
-
const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
|
|
191
|
-
if (!transformers.length)
|
|
192
|
-
return;
|
|
193
|
-
const skipMap = /* @__PURE__ */ new Map();
|
|
194
|
-
let code = original;
|
|
195
|
-
let s = new MagicString(transformSkipCode(code, skipMap, SKIP_COMMENT_RE, "@unocss-skip-placeholder-"));
|
|
196
|
-
const maps = [];
|
|
197
|
-
for (const t of transformers) {
|
|
198
|
-
if (t.idFilter) {
|
|
199
|
-
if (!t.idFilter(id))
|
|
200
|
-
continue;
|
|
201
|
-
} else if (!ctx.filter(code, id)) {
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
await t.transform(s, id, ctx);
|
|
205
|
-
if (s.hasChanged()) {
|
|
206
|
-
code = restoreSkipCode(s.toString(), skipMap);
|
|
207
|
-
maps.push(s.generateMap({ hires: true, source: id }));
|
|
208
|
-
s = new MagicString(code);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
if (code !== original) {
|
|
212
|
-
return {
|
|
213
|
-
code,
|
|
214
|
-
map: remapping(maps, (_, ctx2) => {
|
|
215
|
-
ctx2.content = code;
|
|
216
|
-
return null;
|
|
217
|
-
})
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
223
|
-
const { content } = await ctx.getConfig();
|
|
224
|
-
const { extract, tasks, root, filter } = ctx;
|
|
225
|
-
if (content?.inline) {
|
|
226
|
-
await Promise.all(
|
|
227
|
-
content.inline.map(async (c, idx) => {
|
|
228
|
-
if (typeof c === "function")
|
|
229
|
-
c = await c();
|
|
230
|
-
if (typeof c === "string")
|
|
231
|
-
c = { code: c };
|
|
232
|
-
return extract(c.code, c.id ?? `__plain_content_${idx}__`);
|
|
233
|
-
})
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
if (content?.filesystem) {
|
|
237
|
-
const files = await glob(content.filesystem, { cwd: root, expandDirectories: false });
|
|
238
|
-
async function extractFile(file) {
|
|
239
|
-
file = isAbsolute(file) ? file : resolve(root, file);
|
|
240
|
-
const code = await fs.readFile(file, "utf-8");
|
|
241
|
-
if (!filter(code, file))
|
|
242
|
-
return;
|
|
243
|
-
const preTransform = await applyTransformers(ctx, code, file, "pre");
|
|
244
|
-
const defaultTransform = await applyTransformers(ctx, preTransform?.code || code, file);
|
|
245
|
-
await applyTransformers(ctx, defaultTransform?.code || preTransform?.code || code, file, "post");
|
|
246
|
-
return await extract(preTransform?.code || code, file);
|
|
247
|
-
}
|
|
248
|
-
if (shouldWatch) {
|
|
249
|
-
const { watch } = await import('chokidar');
|
|
250
|
-
const ignored = ["**/{.git,node_modules}/**"];
|
|
251
|
-
const watcher = watch(files, {
|
|
252
|
-
ignorePermissionErrors: true,
|
|
253
|
-
ignored,
|
|
254
|
-
cwd: root,
|
|
255
|
-
ignoreInitial: true
|
|
256
|
-
});
|
|
257
|
-
watcher.on("all", (type, file) => {
|
|
258
|
-
if (type === "add" || type === "change") {
|
|
259
|
-
const absolutePath = resolve(root, file);
|
|
260
|
-
tasks.push(extractFile(absolutePath));
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
await Promise.all(files.map(extractFile));
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
268
|
function getHash(input, length = 8) {
|
|
269
269
|
return createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
270
270
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/webpack",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.62.
|
|
4
|
+
"version": "0.62.4",
|
|
5
5
|
"description": "The Webpack plugin for UnoCSS",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -46,16 +46,16 @@
|
|
|
46
46
|
"@rollup/pluginutils": "^5.1.0",
|
|
47
47
|
"chokidar": "^3.6.0",
|
|
48
48
|
"magic-string": "^0.30.11",
|
|
49
|
-
"tinyglobby": "^0.2.
|
|
50
|
-
"unplugin": "^1.
|
|
49
|
+
"tinyglobby": "^0.2.6",
|
|
50
|
+
"unplugin": "^1.14.1",
|
|
51
51
|
"webpack-sources": "^3.2.3",
|
|
52
|
-
"@unocss/
|
|
53
|
-
"@unocss/
|
|
52
|
+
"@unocss/config": "0.62.4",
|
|
53
|
+
"@unocss/core": "0.62.4"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/webpack": "^5.28.5",
|
|
57
57
|
"@types/webpack-sources": "^3.2.3",
|
|
58
|
-
"webpack": "^5.
|
|
58
|
+
"webpack": "^5.94.0"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "unbuild",
|