@unocss/webpack 0.60.3 → 0.61.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 CHANGED
@@ -162,8 +162,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
162
162
  };
163
163
  }
164
164
 
165
- function getHash(input, length = 8) {
166
- return node_crypto.createHash("sha256").update(input).digest("hex").slice(0, length);
165
+ function getPath(id) {
166
+ return id.replace(/\?.*$/, "");
167
+ }
168
+ function isCssId(id) {
169
+ return core.cssIdRE.test(id);
167
170
  }
168
171
  function hash(str) {
169
172
  let i;
@@ -175,6 +178,22 @@ function hash(str) {
175
178
  }
176
179
  return `00000${(hval >>> 0).toString(36)}`.slice(-6);
177
180
  }
181
+ function transformSkipCode(code, map, SKIP_RULES_RE, keyFlag) {
182
+ for (const item of Array.from(code.matchAll(SKIP_RULES_RE))) {
183
+ if (item != null) {
184
+ const matched = item[0];
185
+ const withHashKey = `${keyFlag}${hash(matched)}`;
186
+ map.set(withHashKey, matched);
187
+ code = code.replace(matched, withHashKey);
188
+ }
189
+ }
190
+ return code;
191
+ }
192
+ function restoreSkipCode(code, map) {
193
+ for (const [withHashKey, matched] of map.entries())
194
+ code = code.replaceAll(withHashKey, matched);
195
+ return code;
196
+ }
178
197
 
179
198
  async function applyTransformers(ctx, original, id, enforce = "default") {
180
199
  if (original.includes(IGNORE_COMMENT))
@@ -184,7 +203,7 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
184
203
  return;
185
204
  const skipMap = /* @__PURE__ */ new Map();
186
205
  let code = original;
187
- let s = new MagicString__default(transformSkipCode(code, skipMap));
206
+ let s = new MagicString__default(transformSkipCode(code, skipMap, SKIP_COMMENT_RE, "@unocss-skip-placeholder-"));
188
207
  const maps = [];
189
208
  for (const t of transformers) {
190
209
  if (t.idFilter) {
@@ -210,22 +229,6 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
210
229
  };
211
230
  }
212
231
  }
213
- function transformSkipCode(code, map) {
214
- for (const item of Array.from(code.matchAll(SKIP_COMMENT_RE))) {
215
- if (item != null) {
216
- const matched = item[0];
217
- const withHashKey = `@unocss-skip-placeholder-${hash(matched)}`;
218
- map.set(withHashKey, matched);
219
- code = code.replace(matched, withHashKey);
220
- }
221
- }
222
- return code;
223
- }
224
- function restoreSkipCode(code, map) {
225
- for (const [withHashKey, matched] of map.entries())
226
- code = code.replace(withHashKey, matched);
227
- return code;
228
- }
229
232
 
230
233
  async function setupContentExtractor(ctx, shouldWatch = false) {
231
234
  const { content } = await ctx.getConfig();
@@ -273,6 +276,10 @@ async function setupContentExtractor(ctx, shouldWatch = false) {
273
276
  }
274
277
  }
275
278
 
279
+ function getHash(input, length = 8) {
280
+ return node_crypto.createHash("sha256").update(input).digest("hex").slice(0, length);
281
+ }
282
+
276
283
  const VIRTUAL_ENTRY_ALIAS = [
277
284
  /^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
278
285
  ];
@@ -316,13 +323,6 @@ function getHashPlaceholder(hash) {
316
323
  return `#--unocss-hash--{content:"${hash}"}`;
317
324
  }
318
325
 
319
- function getPath(id) {
320
- return id.replace(/\?.*$/, "");
321
- }
322
- function isCssId(id) {
323
- return core.cssIdRE.test(id);
324
- }
325
-
326
326
  const PLUGIN_NAME = "unocss:webpack";
327
327
  const UPDATE_DEBOUNCE = 10;
328
328
  function defineConfig(config) {
package/dist/index.mjs CHANGED
@@ -149,8 +149,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
149
149
  };
150
150
  }
151
151
 
152
- function getHash(input, length = 8) {
153
- return createHash("sha256").update(input).digest("hex").slice(0, length);
152
+ function getPath(id) {
153
+ return id.replace(/\?.*$/, "");
154
+ }
155
+ function isCssId(id) {
156
+ return cssIdRE.test(id);
154
157
  }
155
158
  function hash(str) {
156
159
  let i;
@@ -162,6 +165,22 @@ function hash(str) {
162
165
  }
163
166
  return `00000${(hval >>> 0).toString(36)}`.slice(-6);
164
167
  }
168
+ function transformSkipCode(code, map, SKIP_RULES_RE, keyFlag) {
169
+ for (const item of Array.from(code.matchAll(SKIP_RULES_RE))) {
170
+ if (item != null) {
171
+ const matched = item[0];
172
+ const withHashKey = `${keyFlag}${hash(matched)}`;
173
+ map.set(withHashKey, matched);
174
+ code = code.replace(matched, withHashKey);
175
+ }
176
+ }
177
+ return code;
178
+ }
179
+ function restoreSkipCode(code, map) {
180
+ for (const [withHashKey, matched] of map.entries())
181
+ code = code.replaceAll(withHashKey, matched);
182
+ return code;
183
+ }
165
184
 
166
185
  async function applyTransformers(ctx, original, id, enforce = "default") {
167
186
  if (original.includes(IGNORE_COMMENT))
@@ -171,7 +190,7 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
171
190
  return;
172
191
  const skipMap = /* @__PURE__ */ new Map();
173
192
  let code = original;
174
- let s = new MagicString(transformSkipCode(code, skipMap));
193
+ let s = new MagicString(transformSkipCode(code, skipMap, SKIP_COMMENT_RE, "@unocss-skip-placeholder-"));
175
194
  const maps = [];
176
195
  for (const t of transformers) {
177
196
  if (t.idFilter) {
@@ -197,22 +216,6 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
197
216
  };
198
217
  }
199
218
  }
200
- function transformSkipCode(code, map) {
201
- for (const item of Array.from(code.matchAll(SKIP_COMMENT_RE))) {
202
- if (item != null) {
203
- const matched = item[0];
204
- const withHashKey = `@unocss-skip-placeholder-${hash(matched)}`;
205
- map.set(withHashKey, matched);
206
- code = code.replace(matched, withHashKey);
207
- }
208
- }
209
- return code;
210
- }
211
- function restoreSkipCode(code, map) {
212
- for (const [withHashKey, matched] of map.entries())
213
- code = code.replace(withHashKey, matched);
214
- return code;
215
- }
216
219
 
217
220
  async function setupContentExtractor(ctx, shouldWatch = false) {
218
221
  const { content } = await ctx.getConfig();
@@ -260,6 +263,10 @@ async function setupContentExtractor(ctx, shouldWatch = false) {
260
263
  }
261
264
  }
262
265
 
266
+ function getHash(input, length = 8) {
267
+ return createHash("sha256").update(input).digest("hex").slice(0, length);
268
+ }
269
+
263
270
  const VIRTUAL_ENTRY_ALIAS = [
264
271
  /^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
265
272
  ];
@@ -303,13 +310,6 @@ function getHashPlaceholder(hash) {
303
310
  return `#--unocss-hash--{content:"${hash}"}`;
304
311
  }
305
312
 
306
- function getPath(id) {
307
- return id.replace(/\?.*$/, "");
308
- }
309
- function isCssId(id) {
310
- return cssIdRE.test(id);
311
- }
312
-
313
313
  const PLUGIN_NAME = "unocss:webpack";
314
314
  const UPDATE_DEBOUNCE = 10;
315
315
  function defineConfig(config) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/webpack",
3
3
  "type": "module",
4
- "version": "0.60.3",
4
+ "version": "0.61.0",
5
5
  "description": "The Webpack plugin for UnoCSS",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -49,13 +49,13 @@
49
49
  "magic-string": "^0.30.10",
50
50
  "unplugin": "^1.10.1",
51
51
  "webpack-sources": "^3.2.3",
52
- "@unocss/config": "0.60.3",
53
- "@unocss/core": "0.60.3"
52
+ "@unocss/config": "0.61.0",
53
+ "@unocss/core": "0.61.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/webpack": "^5.28.5",
57
57
  "@types/webpack-sources": "^3.2.3",
58
- "webpack": "^5.91.0"
58
+ "webpack": "^5.92.0"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "unbuild",