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