@unocss/webpack 0.62.4 → 0.63.0
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 +15 -460
- package/dist/index.d.cts +1 -2
- package/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.mjs +15 -449
- package/dist/rspack.cjs +21 -0
- package/dist/rspack.d.cts +7 -0
- package/dist/rspack.d.mts +7 -0
- package/dist/rspack.d.ts +7 -0
- package/dist/rspack.mjs +19 -0
- package/dist/shared/webpack.B0TbicgL.mjs +456 -0
- package/dist/shared/webpack.DDjG3x9e.cjs +466 -0
- package/package.json +15 -5
package/dist/index.cjs
CHANGED
|
@@ -1,466 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const unplugin = require('./shared/webpack.DDjG3x9e.cjs');
|
|
4
|
+
require('node:path');
|
|
5
|
+
require('node:process');
|
|
6
|
+
require('unplugin');
|
|
7
|
+
require('webpack-sources');
|
|
8
|
+
require('node:fs/promises');
|
|
9
|
+
require('tinyglobby');
|
|
10
|
+
require('@ampproject/remapping');
|
|
11
|
+
require('magic-string');
|
|
12
|
+
require('@unocss/core');
|
|
13
|
+
require('@rollup/pluginutils');
|
|
14
|
+
require('@unocss/config');
|
|
15
|
+
require('node:crypto');
|
|
4
16
|
|
|
5
|
-
const node_path = require('node:path');
|
|
6
|
-
const process$1 = require('node:process');
|
|
7
|
-
const unplugin = require('unplugin');
|
|
8
|
-
const WebpackSources = require('webpack-sources');
|
|
9
|
-
const fs = require('node:fs/promises');
|
|
10
|
-
const tinyglobby = require('tinyglobby');
|
|
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
|
-
const node_crypto = require('node:crypto');
|
|
17
|
-
|
|
18
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
19
|
-
|
|
20
|
-
const process__default = /*#__PURE__*/_interopDefaultCompat(process$1);
|
|
21
|
-
const WebpackSources__default = /*#__PURE__*/_interopDefaultCompat(WebpackSources);
|
|
22
|
-
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
23
|
-
const remapping__default = /*#__PURE__*/_interopDefaultCompat(remapping);
|
|
24
|
-
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
|
25
|
-
|
|
26
|
-
const INCLUDE_COMMENT = "@unocss-include";
|
|
27
|
-
const IGNORE_COMMENT = "@unocss-ignore";
|
|
28
|
-
const CSS_PLACEHOLDER = "@unocss-placeholder";
|
|
29
|
-
const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
30
|
-
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
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
|
-
|
|
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
|
-
|
|
147
|
-
const defaultPipelineExclude = [core.cssIdRE];
|
|
148
|
-
const defaultPipelineInclude = [/\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/];
|
|
149
|
-
|
|
150
|
-
function deprecationCheck(config) {
|
|
151
|
-
let warned = false;
|
|
152
|
-
function warn(msg) {
|
|
153
|
-
warned = true;
|
|
154
|
-
console.warn(`[unocss] ${msg}`);
|
|
155
|
-
}
|
|
156
|
-
if (config.include)
|
|
157
|
-
warn("`include` option is deprecated, use `content.pipeline.include` instead.");
|
|
158
|
-
if (config.exclude)
|
|
159
|
-
warn("`exclude` option is deprecated, use `content.pipeline.exclude` instead.");
|
|
160
|
-
if (config.extraContent)
|
|
161
|
-
warn("`extraContent` option is deprecated, use `content` instead.");
|
|
162
|
-
if (config.content?.plain)
|
|
163
|
-
warn("`content.plain` option is renamed to `content.inline`.");
|
|
164
|
-
if (warned && typeof process !== "undefined" && process.env.CI)
|
|
165
|
-
throw new Error("deprecation warning");
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function createContext(configOrPath, defaults = {}, extraConfigSources = [], resolveConfigResult = () => {
|
|
169
|
-
}) {
|
|
170
|
-
let root = process__default.cwd();
|
|
171
|
-
let rawConfig = {};
|
|
172
|
-
let configFileList = [];
|
|
173
|
-
const uno = core.createGenerator(rawConfig, defaults);
|
|
174
|
-
let rollupFilter = pluginutils.createFilter(
|
|
175
|
-
defaultPipelineInclude,
|
|
176
|
-
defaultPipelineExclude,
|
|
177
|
-
{ resolve: typeof configOrPath === "string" ? configOrPath : root }
|
|
178
|
-
);
|
|
179
|
-
const invalidations = [];
|
|
180
|
-
const reloadListeners = [];
|
|
181
|
-
const modules = new core.BetterMap();
|
|
182
|
-
const tokens = /* @__PURE__ */ new Set();
|
|
183
|
-
const tasks = [];
|
|
184
|
-
const affectedModules = /* @__PURE__ */ new Set();
|
|
185
|
-
const loadConfig = config.createRecoveryConfigLoader();
|
|
186
|
-
let ready = reloadConfig();
|
|
187
|
-
async function reloadConfig() {
|
|
188
|
-
const result = await loadConfig(root, configOrPath, extraConfigSources, defaults);
|
|
189
|
-
resolveConfigResult(result);
|
|
190
|
-
deprecationCheck(result.config);
|
|
191
|
-
rawConfig = result.config;
|
|
192
|
-
configFileList = result.sources;
|
|
193
|
-
uno.setConfig(rawConfig);
|
|
194
|
-
uno.config.envMode = "dev";
|
|
195
|
-
rollupFilter = rawConfig.content?.pipeline === false ? () => false : pluginutils.createFilter(
|
|
196
|
-
rawConfig.content?.pipeline?.include || rawConfig.include || defaultPipelineInclude,
|
|
197
|
-
rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude,
|
|
198
|
-
{ resolve: typeof configOrPath === "string" ? configOrPath : root }
|
|
199
|
-
);
|
|
200
|
-
tokens.clear();
|
|
201
|
-
await Promise.all(modules.map((code, id) => uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens)));
|
|
202
|
-
invalidate();
|
|
203
|
-
dispatchReload();
|
|
204
|
-
const presets = /* @__PURE__ */ new Set();
|
|
205
|
-
uno.config.presets.forEach((i) => {
|
|
206
|
-
if (!i.name)
|
|
207
|
-
return;
|
|
208
|
-
if (presets.has(i.name))
|
|
209
|
-
console.warn(`[unocss] duplication of preset ${i.name} found, there might be something wrong with your config.`);
|
|
210
|
-
else
|
|
211
|
-
presets.add(i.name);
|
|
212
|
-
});
|
|
213
|
-
return result;
|
|
214
|
-
}
|
|
215
|
-
async function updateRoot(newRoot) {
|
|
216
|
-
if (newRoot !== root) {
|
|
217
|
-
root = newRoot;
|
|
218
|
-
ready = reloadConfig();
|
|
219
|
-
}
|
|
220
|
-
return await ready;
|
|
221
|
-
}
|
|
222
|
-
function invalidate() {
|
|
223
|
-
invalidations.forEach((cb) => cb());
|
|
224
|
-
}
|
|
225
|
-
function dispatchReload() {
|
|
226
|
-
reloadListeners.forEach((cb) => cb());
|
|
227
|
-
}
|
|
228
|
-
async function extract(code, id) {
|
|
229
|
-
if (id)
|
|
230
|
-
modules.set(id, code);
|
|
231
|
-
const len = tokens.size;
|
|
232
|
-
await uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
|
|
233
|
-
if (tokens.size > len)
|
|
234
|
-
invalidate();
|
|
235
|
-
}
|
|
236
|
-
function filter(code, id) {
|
|
237
|
-
if (code.includes(IGNORE_COMMENT))
|
|
238
|
-
return false;
|
|
239
|
-
return code.includes(INCLUDE_COMMENT) || code.includes(CSS_PLACEHOLDER) || rollupFilter(id.replace(/\?v=\w+$/, ""));
|
|
240
|
-
}
|
|
241
|
-
async function getConfig() {
|
|
242
|
-
await ready;
|
|
243
|
-
return rawConfig;
|
|
244
|
-
}
|
|
245
|
-
async function flushTasks() {
|
|
246
|
-
const _tasks = [...tasks];
|
|
247
|
-
await Promise.all(_tasks);
|
|
248
|
-
if (tasks[0] === _tasks[0])
|
|
249
|
-
tasks.splice(0, _tasks.length);
|
|
250
|
-
}
|
|
251
|
-
return {
|
|
252
|
-
get ready() {
|
|
253
|
-
return ready;
|
|
254
|
-
},
|
|
255
|
-
tokens,
|
|
256
|
-
modules,
|
|
257
|
-
affectedModules,
|
|
258
|
-
tasks,
|
|
259
|
-
flushTasks,
|
|
260
|
-
invalidate,
|
|
261
|
-
onInvalidate(fn) {
|
|
262
|
-
invalidations.push(fn);
|
|
263
|
-
},
|
|
264
|
-
filter,
|
|
265
|
-
reloadConfig,
|
|
266
|
-
onReload(fn) {
|
|
267
|
-
reloadListeners.push(fn);
|
|
268
|
-
},
|
|
269
|
-
uno,
|
|
270
|
-
extract,
|
|
271
|
-
getConfig,
|
|
272
|
-
get root() {
|
|
273
|
-
return root;
|
|
274
|
-
},
|
|
275
|
-
updateRoot,
|
|
276
|
-
getConfigFileList: () => configFileList
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
function getHash(input, length = 8) {
|
|
281
|
-
return node_crypto.createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const VIRTUAL_ENTRY_ALIAS = [
|
|
285
|
-
/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
|
|
286
|
-
];
|
|
287
|
-
const LAYER_MARK_ALL = "__ALL__";
|
|
288
|
-
const RESOLVED_ID_WITH_QUERY_RE = /[/\\]__uno(_.*?)?\.css(\?.*)?$/;
|
|
289
|
-
const RESOLVED_ID_RE = /[/\\]__uno(?:_(.*?))?\.css$/;
|
|
290
|
-
function resolveId(id) {
|
|
291
|
-
if (id.match(RESOLVED_ID_WITH_QUERY_RE))
|
|
292
|
-
return id;
|
|
293
|
-
for (const alias of VIRTUAL_ENTRY_ALIAS) {
|
|
294
|
-
const match = id.match(alias);
|
|
295
|
-
if (match) {
|
|
296
|
-
return match[1] ? `/__uno_${match[1]}.css` : "/__uno.css";
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
function resolveLayer(id) {
|
|
301
|
-
const match = id.match(RESOLVED_ID_RE);
|
|
302
|
-
if (match)
|
|
303
|
-
return match[1] || LAYER_MARK_ALL;
|
|
304
|
-
}
|
|
305
|
-
const LAYER_PLACEHOLDER_RE = /#--unocss--\s*\{\s*layer\s*:\s*(.+?)\s*(?:;\s*escape-view\s*:\s*(.+?)\s*)?;?\s*\}/g;
|
|
306
|
-
function getLayerPlaceholder(layer) {
|
|
307
|
-
return `#--unocss--{layer:${layer};escape-view:\\"\\'\\\`\\\\}`;
|
|
308
|
-
}
|
|
309
|
-
function getCssEscaperForJsContent(view) {
|
|
310
|
-
if (!view)
|
|
311
|
-
return (css) => css;
|
|
312
|
-
const prefix = {};
|
|
313
|
-
const escapeViewRe = /(\\*)\\(["'`\\])/g;
|
|
314
|
-
view.trim().replace(escapeViewRe, (_, bs, char) => {
|
|
315
|
-
prefix[char] = bs.replace(/\\\\/g, "\\");
|
|
316
|
-
return "";
|
|
317
|
-
});
|
|
318
|
-
return (css) => css.replace(/["'`\\]/g, (v) => {
|
|
319
|
-
return (prefix[v] || "") + v;
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
const HASH_PLACEHOLDER_RE = /#--unocss-hash--\s*\{\s*content\s*:\s*\\*"([^\\"]+)\\*";?\s*\}/g;
|
|
323
|
-
function getHashPlaceholder(hash) {
|
|
324
|
-
return `#--unocss-hash--{content:"${hash}"}`;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
const PLUGIN_NAME = "unocss:webpack";
|
|
328
|
-
const UPDATE_DEBOUNCE = 10;
|
|
329
|
-
function defineConfig(config) {
|
|
330
|
-
return config;
|
|
331
|
-
}
|
|
332
17
|
function WebpackPlugin(configOrPath, defaults) {
|
|
333
|
-
return unplugin.
|
|
334
|
-
const ctx = createContext(configOrPath, {
|
|
335
|
-
envMode: process__default.env.NODE_ENV === "development" ? "dev" : "build",
|
|
336
|
-
...defaults
|
|
337
|
-
});
|
|
338
|
-
const { uno, tokens, filter, extract, onInvalidate, tasks, flushTasks } = ctx;
|
|
339
|
-
let timer;
|
|
340
|
-
onInvalidate(() => {
|
|
341
|
-
clearTimeout(timer);
|
|
342
|
-
timer = setTimeout(updateModules, UPDATE_DEBOUNCE);
|
|
343
|
-
});
|
|
344
|
-
const nonPreTransformers = ctx.uno.config.transformers?.filter((i) => i.enforce !== "pre");
|
|
345
|
-
if (nonPreTransformers?.length) {
|
|
346
|
-
console.warn(
|
|
347
|
-
// eslint-disable-next-line prefer-template
|
|
348
|
-
'[unocss] webpack integration only supports "pre" enforce transformers currently.the following transformers will be ignored\n' + nonPreTransformers.map((i) => ` - ${i.name}`).join("\n")
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
tasks.push(setupContentExtractor(ctx, typeof configOrPath === "object" && configOrPath?.watch));
|
|
352
|
-
const entries = /* @__PURE__ */ new Set();
|
|
353
|
-
const hashes = /* @__PURE__ */ new Map();
|
|
354
|
-
const plugin = {
|
|
355
|
-
name: "unocss:webpack",
|
|
356
|
-
enforce: "pre",
|
|
357
|
-
transformInclude(id) {
|
|
358
|
-
return filter("", id) && !id.endsWith(".html") && !RESOLVED_ID_RE.test(id);
|
|
359
|
-
},
|
|
360
|
-
async transform(code, id) {
|
|
361
|
-
const result = await applyTransformers(ctx, code, id, "pre");
|
|
362
|
-
if (isCssId(id))
|
|
363
|
-
return result;
|
|
364
|
-
if (result == null)
|
|
365
|
-
tasks.push(extract(code, id));
|
|
366
|
-
else
|
|
367
|
-
tasks.push(extract(result.code, id));
|
|
368
|
-
return result;
|
|
369
|
-
},
|
|
370
|
-
resolveId(id) {
|
|
371
|
-
const entry = resolveId(id);
|
|
372
|
-
if (entry === id)
|
|
373
|
-
return;
|
|
374
|
-
if (entry) {
|
|
375
|
-
let query = "";
|
|
376
|
-
const queryIndex = id.indexOf("?");
|
|
377
|
-
if (queryIndex >= 0)
|
|
378
|
-
query = id.slice(queryIndex);
|
|
379
|
-
entries.add(entry);
|
|
380
|
-
return entry + query;
|
|
381
|
-
}
|
|
382
|
-
},
|
|
383
|
-
loadInclude(id) {
|
|
384
|
-
const layer = getLayer(id);
|
|
385
|
-
return !!layer;
|
|
386
|
-
},
|
|
387
|
-
// serve the placeholders in virtual module
|
|
388
|
-
load(id) {
|
|
389
|
-
const layer = getLayer(id);
|
|
390
|
-
const hash = hashes.get(id);
|
|
391
|
-
if (layer)
|
|
392
|
-
return (hash ? getHashPlaceholder(hash) : "") + getLayerPlaceholder(layer);
|
|
393
|
-
},
|
|
394
|
-
webpack(compiler) {
|
|
395
|
-
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
396
|
-
const optimizeAssetsHook = (
|
|
397
|
-
/* webpack 5 & 6 */
|
|
398
|
-
compilation.hooks.processAssets || /* webpack 4 */
|
|
399
|
-
compilation.hooks.optimizeAssets
|
|
400
|
-
);
|
|
401
|
-
optimizeAssetsHook.tapPromise(PLUGIN_NAME, async () => {
|
|
402
|
-
const files = Object.keys(compilation.assets);
|
|
403
|
-
await flushTasks();
|
|
404
|
-
const result = await uno.generate(tokens, { minify: true });
|
|
405
|
-
for (const file of files) {
|
|
406
|
-
if (file === "*")
|
|
407
|
-
return;
|
|
408
|
-
let code = compilation.assets[file].source().toString();
|
|
409
|
-
let escapeCss;
|
|
410
|
-
let replaced = false;
|
|
411
|
-
code = code.replace(HASH_PLACEHOLDER_RE, "");
|
|
412
|
-
code = code.replace(LAYER_PLACEHOLDER_RE, (_, layer, escapeView) => {
|
|
413
|
-
replaced = true;
|
|
414
|
-
const css = layer.trim() === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries).map((i) => resolveLayer(i)).filter((i) => !!i)) : result.getLayer(layer) || "";
|
|
415
|
-
escapeCss = escapeCss ?? getCssEscaperForJsContent(escapeView.trim());
|
|
416
|
-
return escapeCss(css);
|
|
417
|
-
});
|
|
418
|
-
if (replaced)
|
|
419
|
-
compilation.assets[file] = new WebpackSources__default.SourceMapSource(code, file, compilation.assets[file].map());
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
let lastTokenSize = tokens.size;
|
|
426
|
-
async function updateModules() {
|
|
427
|
-
if (!plugin.__vfsModules)
|
|
428
|
-
return;
|
|
429
|
-
await flushTasks();
|
|
430
|
-
const result = await uno.generate(tokens);
|
|
431
|
-
if (lastTokenSize === tokens.size)
|
|
432
|
-
return;
|
|
433
|
-
lastTokenSize = tokens.size;
|
|
434
|
-
Array.from(plugin.__vfsModules).forEach((id) => {
|
|
435
|
-
let path = decodeURIComponent(id.slice(plugin.__virtualModulePrefix.length));
|
|
436
|
-
path = normalizeAbsolutePath(path);
|
|
437
|
-
const layer = resolveLayer(path);
|
|
438
|
-
if (!layer)
|
|
439
|
-
return;
|
|
440
|
-
const code = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries).map((i) => resolveLayer(i)).filter((i) => !!i)) : result.getLayer(layer) || "";
|
|
441
|
-
const hash = getHash(code);
|
|
442
|
-
hashes.set(path, hash);
|
|
443
|
-
plugin.__vfs.writeModule(id, code);
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
return plugin;
|
|
447
|
-
}).webpack();
|
|
448
|
-
}
|
|
449
|
-
function getLayer(id) {
|
|
450
|
-
let layer = resolveLayer(getPath(id));
|
|
451
|
-
if (!layer) {
|
|
452
|
-
const entry = resolveId(id);
|
|
453
|
-
if (entry)
|
|
454
|
-
layer = resolveLayer(entry);
|
|
455
|
-
}
|
|
456
|
-
return layer;
|
|
457
|
-
}
|
|
458
|
-
function normalizeAbsolutePath(path) {
|
|
459
|
-
if (node_path.isAbsolute(path))
|
|
460
|
-
return node_path.normalize(path);
|
|
461
|
-
else
|
|
462
|
-
return path;
|
|
18
|
+
return unplugin.unplugin(configOrPath, defaults).webpack();
|
|
463
19
|
}
|
|
464
20
|
|
|
465
|
-
exports
|
|
466
|
-
exports.defineConfig = defineConfig;
|
|
21
|
+
module.exports = WebpackPlugin;
|
package/dist/index.d.cts
CHANGED
|
@@ -9,8 +9,7 @@ interface WebpackPluginOptions<Theme extends object = object> extends UserConfig
|
|
|
9
9
|
*/
|
|
10
10
|
watch?: boolean;
|
|
11
11
|
}
|
|
12
|
-
declare function defineConfig<Theme extends object>(config: WebpackPluginOptions<Theme>): WebpackPluginOptions<Theme>;
|
|
13
12
|
declare function WebpackPlugin<Theme extends object>(configOrPath?: WebpackPluginOptions<Theme> | string, defaults?: UserConfigDefaults): webpack.WebpackPluginInstance;
|
|
14
13
|
|
|
15
14
|
export = WebpackPlugin;
|
|
16
|
-
export { type WebpackPluginOptions
|
|
15
|
+
export { type WebpackPluginOptions };
|
package/dist/index.d.mts
CHANGED
|
@@ -9,7 +9,6 @@ interface WebpackPluginOptions<Theme extends object = object> extends UserConfig
|
|
|
9
9
|
*/
|
|
10
10
|
watch?: boolean;
|
|
11
11
|
}
|
|
12
|
-
declare function defineConfig<Theme extends object>(config: WebpackPluginOptions<Theme>): WebpackPluginOptions<Theme>;
|
|
13
12
|
declare function WebpackPlugin<Theme extends object>(configOrPath?: WebpackPluginOptions<Theme> | string, defaults?: UserConfigDefaults): webpack.WebpackPluginInstance;
|
|
14
13
|
|
|
15
|
-
export { type WebpackPluginOptions, WebpackPlugin as default
|
|
14
|
+
export { type WebpackPluginOptions, WebpackPlugin as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,8 +9,7 @@ interface WebpackPluginOptions<Theme extends object = object> extends UserConfig
|
|
|
9
9
|
*/
|
|
10
10
|
watch?: boolean;
|
|
11
11
|
}
|
|
12
|
-
declare function defineConfig<Theme extends object>(config: WebpackPluginOptions<Theme>): WebpackPluginOptions<Theme>;
|
|
13
12
|
declare function WebpackPlugin<Theme extends object>(configOrPath?: WebpackPluginOptions<Theme> | string, defaults?: UserConfigDefaults): webpack.WebpackPluginInstance;
|
|
14
13
|
|
|
15
14
|
export = WebpackPlugin;
|
|
16
|
-
export { type WebpackPluginOptions
|
|
15
|
+
export { type WebpackPluginOptions };
|