@unocss/webpack 0.53.1 → 0.53.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +38 -8
- package/dist/index.mjs +38 -8
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -25,6 +25,9 @@ const remapping__default = /*#__PURE__*/_interopDefaultLegacy(remapping);
|
|
|
25
25
|
const INCLUDE_COMMENT = "@unocss-include";
|
|
26
26
|
const IGNORE_COMMENT = "@unocss-ignore";
|
|
27
27
|
const CSS_PLACEHOLDER = "@unocss-placeholder";
|
|
28
|
+
const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
29
|
+
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
30
|
+
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");
|
|
28
31
|
|
|
29
32
|
const defaultPipelineExclude = [core.cssIdRE];
|
|
30
33
|
const defaultPipelineInclude = [/\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/];
|
|
@@ -74,7 +77,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
74
77
|
rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude
|
|
75
78
|
);
|
|
76
79
|
tokens.clear();
|
|
77
|
-
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
80
|
+
await Promise.all(modules.map((code, id) => uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens)));
|
|
78
81
|
invalidate();
|
|
79
82
|
dispatchReload();
|
|
80
83
|
const presets = /* @__PURE__ */ new Set();
|
|
@@ -105,7 +108,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
105
108
|
if (id)
|
|
106
109
|
modules.set(id, code);
|
|
107
110
|
const len = tokens.size;
|
|
108
|
-
await uno.applyExtractors(code, id, tokens);
|
|
111
|
+
await uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
|
|
109
112
|
if (tokens.size > len)
|
|
110
113
|
invalidate();
|
|
111
114
|
}
|
|
@@ -150,14 +153,29 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
150
153
|
};
|
|
151
154
|
}
|
|
152
155
|
|
|
156
|
+
function getHash(input, length = 8) {
|
|
157
|
+
return node_crypto.createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
158
|
+
}
|
|
159
|
+
function hash(str) {
|
|
160
|
+
let i;
|
|
161
|
+
let l;
|
|
162
|
+
let hval = 2166136261;
|
|
163
|
+
for (i = 0, l = str.length; i < l; i++) {
|
|
164
|
+
hval ^= str.charCodeAt(i);
|
|
165
|
+
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
166
|
+
}
|
|
167
|
+
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
168
|
+
}
|
|
169
|
+
|
|
153
170
|
async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
154
171
|
if (original.includes(IGNORE_COMMENT))
|
|
155
172
|
return;
|
|
156
173
|
const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
|
|
157
174
|
if (!transformers.length)
|
|
158
175
|
return;
|
|
176
|
+
const skipMap = /* @__PURE__ */ new Map();
|
|
159
177
|
let code = original;
|
|
160
|
-
let s = new MagicString__default(code);
|
|
178
|
+
let s = new MagicString__default(transformSkipCode(code, skipMap));
|
|
161
179
|
const maps = [];
|
|
162
180
|
for (const t of transformers) {
|
|
163
181
|
if (t.idFilter) {
|
|
@@ -168,7 +186,7 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
168
186
|
}
|
|
169
187
|
await t.transform(s, id, ctx);
|
|
170
188
|
if (s.hasChanged()) {
|
|
171
|
-
code = s.toString();
|
|
189
|
+
code = restoreSkipCode(s.toString(), skipMap);
|
|
172
190
|
maps.push(s.generateMap({ hires: true, source: id }));
|
|
173
191
|
s = new MagicString__default(code);
|
|
174
192
|
}
|
|
@@ -181,6 +199,22 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
181
199
|
};
|
|
182
200
|
}
|
|
183
201
|
}
|
|
202
|
+
function transformSkipCode(code, map) {
|
|
203
|
+
for (const item of Array.from(code.matchAll(SKIP_COMMENT_RE))) {
|
|
204
|
+
if (item != null) {
|
|
205
|
+
const matched = item[0];
|
|
206
|
+
const withHashKey = `@unocss-skip-placeholder-${hash(matched)}`;
|
|
207
|
+
map.set(withHashKey, matched);
|
|
208
|
+
code = code.replace(matched, withHashKey);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return code;
|
|
212
|
+
}
|
|
213
|
+
function restoreSkipCode(code, map) {
|
|
214
|
+
for (const [withHashKey, matched] of map.entries())
|
|
215
|
+
code = code.replace(withHashKey, matched);
|
|
216
|
+
return code;
|
|
217
|
+
}
|
|
184
218
|
|
|
185
219
|
async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
186
220
|
const { content } = await ctx.getConfig();
|
|
@@ -227,10 +261,6 @@ async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
|
227
261
|
}
|
|
228
262
|
}
|
|
229
263
|
|
|
230
|
-
function getHash(input, length = 8) {
|
|
231
|
-
return node_crypto.createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
264
|
const VIRTUAL_ENTRY_ALIAS = [
|
|
235
265
|
/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
|
|
236
266
|
];
|
package/dist/index.mjs
CHANGED
|
@@ -13,6 +13,9 @@ import { createHash } from 'node:crypto';
|
|
|
13
13
|
const INCLUDE_COMMENT = "@unocss-include";
|
|
14
14
|
const IGNORE_COMMENT = "@unocss-ignore";
|
|
15
15
|
const CSS_PLACEHOLDER = "@unocss-placeholder";
|
|
16
|
+
const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
17
|
+
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
18
|
+
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");
|
|
16
19
|
|
|
17
20
|
const defaultPipelineExclude = [cssIdRE];
|
|
18
21
|
const defaultPipelineInclude = [/\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/];
|
|
@@ -62,7 +65,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
62
65
|
rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude
|
|
63
66
|
);
|
|
64
67
|
tokens.clear();
|
|
65
|
-
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
68
|
+
await Promise.all(modules.map((code, id) => uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens)));
|
|
66
69
|
invalidate();
|
|
67
70
|
dispatchReload();
|
|
68
71
|
const presets = /* @__PURE__ */ new Set();
|
|
@@ -93,7 +96,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
93
96
|
if (id)
|
|
94
97
|
modules.set(id, code);
|
|
95
98
|
const len = tokens.size;
|
|
96
|
-
await uno.applyExtractors(code, id, tokens);
|
|
99
|
+
await uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
|
|
97
100
|
if (tokens.size > len)
|
|
98
101
|
invalidate();
|
|
99
102
|
}
|
|
@@ -138,14 +141,29 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
138
141
|
};
|
|
139
142
|
}
|
|
140
143
|
|
|
144
|
+
function getHash(input, length = 8) {
|
|
145
|
+
return createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
146
|
+
}
|
|
147
|
+
function hash(str) {
|
|
148
|
+
let i;
|
|
149
|
+
let l;
|
|
150
|
+
let hval = 2166136261;
|
|
151
|
+
for (i = 0, l = str.length; i < l; i++) {
|
|
152
|
+
hval ^= str.charCodeAt(i);
|
|
153
|
+
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
154
|
+
}
|
|
155
|
+
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
156
|
+
}
|
|
157
|
+
|
|
141
158
|
async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
142
159
|
if (original.includes(IGNORE_COMMENT))
|
|
143
160
|
return;
|
|
144
161
|
const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
|
|
145
162
|
if (!transformers.length)
|
|
146
163
|
return;
|
|
164
|
+
const skipMap = /* @__PURE__ */ new Map();
|
|
147
165
|
let code = original;
|
|
148
|
-
let s = new MagicString(code);
|
|
166
|
+
let s = new MagicString(transformSkipCode(code, skipMap));
|
|
149
167
|
const maps = [];
|
|
150
168
|
for (const t of transformers) {
|
|
151
169
|
if (t.idFilter) {
|
|
@@ -156,7 +174,7 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
156
174
|
}
|
|
157
175
|
await t.transform(s, id, ctx);
|
|
158
176
|
if (s.hasChanged()) {
|
|
159
|
-
code = s.toString();
|
|
177
|
+
code = restoreSkipCode(s.toString(), skipMap);
|
|
160
178
|
maps.push(s.generateMap({ hires: true, source: id }));
|
|
161
179
|
s = new MagicString(code);
|
|
162
180
|
}
|
|
@@ -169,6 +187,22 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
169
187
|
};
|
|
170
188
|
}
|
|
171
189
|
}
|
|
190
|
+
function transformSkipCode(code, map) {
|
|
191
|
+
for (const item of Array.from(code.matchAll(SKIP_COMMENT_RE))) {
|
|
192
|
+
if (item != null) {
|
|
193
|
+
const matched = item[0];
|
|
194
|
+
const withHashKey = `@unocss-skip-placeholder-${hash(matched)}`;
|
|
195
|
+
map.set(withHashKey, matched);
|
|
196
|
+
code = code.replace(matched, withHashKey);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return code;
|
|
200
|
+
}
|
|
201
|
+
function restoreSkipCode(code, map) {
|
|
202
|
+
for (const [withHashKey, matched] of map.entries())
|
|
203
|
+
code = code.replace(withHashKey, matched);
|
|
204
|
+
return code;
|
|
205
|
+
}
|
|
172
206
|
|
|
173
207
|
async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
174
208
|
const { content } = await ctx.getConfig();
|
|
@@ -215,10 +249,6 @@ async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
|
215
249
|
}
|
|
216
250
|
}
|
|
217
251
|
|
|
218
|
-
function getHash(input, length = 8) {
|
|
219
|
-
return createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
252
|
const VIRTUAL_ENTRY_ALIAS = [
|
|
223
253
|
/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
|
|
224
254
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/webpack",
|
|
3
|
-
"version": "0.53.
|
|
3
|
+
"version": "0.53.3",
|
|
4
4
|
"description": "The Webpack plugin for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"magic-string": "^0.30.0",
|
|
44
44
|
"unplugin": "^1.3.1",
|
|
45
45
|
"webpack-sources": "^3.2.3",
|
|
46
|
-
"@unocss/config": "0.53.
|
|
47
|
-
"@unocss/core": "0.53.
|
|
46
|
+
"@unocss/config": "0.53.3",
|
|
47
|
+
"@unocss/core": "0.53.3"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/webpack": "^5.28.1",
|
|
51
51
|
"@types/webpack-sources": "^3.2.0",
|
|
52
|
-
"webpack": "^5.
|
|
52
|
+
"webpack": "^5.88.0"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "unbuild",
|