@unocss/webpack 0.64.1 → 0.65.0-beta.1
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
package/dist/index.mjs
CHANGED
package/dist/rspack.cjs
CHANGED
package/dist/rspack.mjs
CHANGED
|
@@ -168,7 +168,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
168
168
|
let root = process__default.cwd();
|
|
169
169
|
let rawConfig = {};
|
|
170
170
|
let configFileList = [];
|
|
171
|
-
|
|
171
|
+
let uno;
|
|
172
|
+
const _uno = core.createGenerator(rawConfig, defaults).then((r) => {
|
|
173
|
+
uno = r;
|
|
174
|
+
return r;
|
|
175
|
+
});
|
|
172
176
|
let rollupFilter = pluginutils.createFilter(
|
|
173
177
|
defaultPipelineInclude,
|
|
174
178
|
defaultPipelineExclude,
|
|
@@ -183,12 +187,13 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
183
187
|
const loadConfig = config.createRecoveryConfigLoader();
|
|
184
188
|
let ready = reloadConfig();
|
|
185
189
|
async function reloadConfig() {
|
|
190
|
+
await _uno;
|
|
186
191
|
const result = await loadConfig(root, configOrPath, extraConfigSources, defaults);
|
|
187
192
|
resolveConfigResult(result);
|
|
188
193
|
deprecationCheck(result.config);
|
|
189
194
|
rawConfig = result.config;
|
|
190
195
|
configFileList = result.sources;
|
|
191
|
-
uno.setConfig(rawConfig);
|
|
196
|
+
await uno.setConfig(rawConfig);
|
|
192
197
|
uno.config.envMode = "dev";
|
|
193
198
|
rollupFilter = rawConfig.content?.pipeline === false ? () => false : pluginutils.createFilter(
|
|
194
199
|
rawConfig.content?.pipeline?.include || rawConfig.include || defaultPipelineInclude,
|
|
@@ -215,10 +220,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
215
220
|
reloadListeners.forEach((cb) => cb());
|
|
216
221
|
}
|
|
217
222
|
async function extract(code, id) {
|
|
223
|
+
const uno2 = await _uno;
|
|
218
224
|
if (id)
|
|
219
225
|
modules.set(id, code);
|
|
220
226
|
const len = tokens.size;
|
|
221
|
-
await
|
|
227
|
+
await uno2.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
|
|
222
228
|
if (tokens.size > len)
|
|
223
229
|
invalidate();
|
|
224
230
|
}
|
|
@@ -255,7 +261,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
255
261
|
onReload(fn) {
|
|
256
262
|
reloadListeners.push(fn);
|
|
257
263
|
},
|
|
258
|
-
uno
|
|
264
|
+
get uno() {
|
|
265
|
+
if (!uno)
|
|
266
|
+
throw new Error("Run `await context.ready` before accessing `context.uno`");
|
|
267
|
+
return uno;
|
|
268
|
+
},
|
|
259
269
|
extract,
|
|
260
270
|
getConfig,
|
|
261
271
|
get root() {
|
|
@@ -321,19 +331,12 @@ function unplugin(configOrPath, defaults) {
|
|
|
321
331
|
envMode: process__default.env.NODE_ENV === "development" ? "dev" : "build",
|
|
322
332
|
...defaults
|
|
323
333
|
});
|
|
324
|
-
const {
|
|
334
|
+
const { tokens, filter, extract, onInvalidate, tasks, flushTasks } = ctx;
|
|
325
335
|
let timer;
|
|
326
336
|
onInvalidate(() => {
|
|
327
337
|
clearTimeout(timer);
|
|
328
338
|
timer = setTimeout(updateModules, UPDATE_DEBOUNCE);
|
|
329
339
|
});
|
|
330
|
-
const nonPreTransformers = ctx.uno.config.transformers?.filter((i) => i.enforce !== "pre");
|
|
331
|
-
if (nonPreTransformers?.length) {
|
|
332
|
-
console.warn(
|
|
333
|
-
// eslint-disable-next-line prefer-template
|
|
334
|
-
'[unocss] webpack integration only supports "pre" enforce transformers currently.the following transformers will be ignored\n' + nonPreTransformers.map((i) => ` - ${i.name}`).join("\n")
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
340
|
tasks.push(setupContentExtractor(ctx, typeof configOrPath === "object" && configOrPath?.watch));
|
|
338
341
|
const entries = /* @__PURE__ */ new Set();
|
|
339
342
|
const hashes = /* @__PURE__ */ new Map();
|
|
@@ -380,6 +383,13 @@ function unplugin(configOrPath, defaults) {
|
|
|
380
383
|
webpack(compiler) {
|
|
381
384
|
compiler.hooks.beforeCompile.tapPromise(PLUGIN_NAME, async () => {
|
|
382
385
|
await ctx.ready;
|
|
386
|
+
const nonPreTransformers = ctx.uno.config.transformers?.filter((i) => i.enforce !== "pre");
|
|
387
|
+
if (nonPreTransformers?.length) {
|
|
388
|
+
console.warn(
|
|
389
|
+
// eslint-disable-next-line prefer-template
|
|
390
|
+
'[unocss] webpack integration only supports "pre" enforce transformers currently.the following transformers will be ignored\n' + nonPreTransformers.map((i) => ` - ${i.name}`).join("\n")
|
|
391
|
+
);
|
|
392
|
+
}
|
|
383
393
|
});
|
|
384
394
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
385
395
|
const optimizeAssetsHook = (
|
|
@@ -388,9 +398,10 @@ function unplugin(configOrPath, defaults) {
|
|
|
388
398
|
compilation.hooks.optimizeAssets
|
|
389
399
|
);
|
|
390
400
|
optimizeAssetsHook.tapPromise(PLUGIN_NAME, async () => {
|
|
401
|
+
await ctx.ready;
|
|
391
402
|
const files = Object.keys(compilation.assets);
|
|
392
403
|
await flushTasks();
|
|
393
|
-
const result = await uno.generate(tokens, { minify: true });
|
|
404
|
+
const result = await ctx.uno.generate(tokens, { minify: true });
|
|
394
405
|
for (const file of files) {
|
|
395
406
|
if (file === "*")
|
|
396
407
|
return;
|
|
@@ -419,7 +430,7 @@ function unplugin(configOrPath, defaults) {
|
|
|
419
430
|
if (!plugin.__vfsModules)
|
|
420
431
|
return;
|
|
421
432
|
await flushTasks();
|
|
422
|
-
const result = await uno.generate(tokens);
|
|
433
|
+
const result = await ctx.uno.generate(tokens);
|
|
423
434
|
if (lastTokenSize === tokens.size)
|
|
424
435
|
return;
|
|
425
436
|
lastTokenSize = tokens.size;
|
|
@@ -158,7 +158,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
158
158
|
let root = process$1.cwd();
|
|
159
159
|
let rawConfig = {};
|
|
160
160
|
let configFileList = [];
|
|
161
|
-
|
|
161
|
+
let uno;
|
|
162
|
+
const _uno = createGenerator(rawConfig, defaults).then((r) => {
|
|
163
|
+
uno = r;
|
|
164
|
+
return r;
|
|
165
|
+
});
|
|
162
166
|
let rollupFilter = createFilter(
|
|
163
167
|
defaultPipelineInclude,
|
|
164
168
|
defaultPipelineExclude,
|
|
@@ -173,12 +177,13 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
173
177
|
const loadConfig = createRecoveryConfigLoader();
|
|
174
178
|
let ready = reloadConfig();
|
|
175
179
|
async function reloadConfig() {
|
|
180
|
+
await _uno;
|
|
176
181
|
const result = await loadConfig(root, configOrPath, extraConfigSources, defaults);
|
|
177
182
|
resolveConfigResult(result);
|
|
178
183
|
deprecationCheck(result.config);
|
|
179
184
|
rawConfig = result.config;
|
|
180
185
|
configFileList = result.sources;
|
|
181
|
-
uno.setConfig(rawConfig);
|
|
186
|
+
await uno.setConfig(rawConfig);
|
|
182
187
|
uno.config.envMode = "dev";
|
|
183
188
|
rollupFilter = rawConfig.content?.pipeline === false ? () => false : createFilter(
|
|
184
189
|
rawConfig.content?.pipeline?.include || rawConfig.include || defaultPipelineInclude,
|
|
@@ -205,10 +210,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
205
210
|
reloadListeners.forEach((cb) => cb());
|
|
206
211
|
}
|
|
207
212
|
async function extract(code, id) {
|
|
213
|
+
const uno2 = await _uno;
|
|
208
214
|
if (id)
|
|
209
215
|
modules.set(id, code);
|
|
210
216
|
const len = tokens.size;
|
|
211
|
-
await
|
|
217
|
+
await uno2.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
|
|
212
218
|
if (tokens.size > len)
|
|
213
219
|
invalidate();
|
|
214
220
|
}
|
|
@@ -245,7 +251,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
245
251
|
onReload(fn) {
|
|
246
252
|
reloadListeners.push(fn);
|
|
247
253
|
},
|
|
248
|
-
uno
|
|
254
|
+
get uno() {
|
|
255
|
+
if (!uno)
|
|
256
|
+
throw new Error("Run `await context.ready` before accessing `context.uno`");
|
|
257
|
+
return uno;
|
|
258
|
+
},
|
|
249
259
|
extract,
|
|
250
260
|
getConfig,
|
|
251
261
|
get root() {
|
|
@@ -311,19 +321,12 @@ function unplugin(configOrPath, defaults) {
|
|
|
311
321
|
envMode: process$1.env.NODE_ENV === "development" ? "dev" : "build",
|
|
312
322
|
...defaults
|
|
313
323
|
});
|
|
314
|
-
const {
|
|
324
|
+
const { tokens, filter, extract, onInvalidate, tasks, flushTasks } = ctx;
|
|
315
325
|
let timer;
|
|
316
326
|
onInvalidate(() => {
|
|
317
327
|
clearTimeout(timer);
|
|
318
328
|
timer = setTimeout(updateModules, UPDATE_DEBOUNCE);
|
|
319
329
|
});
|
|
320
|
-
const nonPreTransformers = ctx.uno.config.transformers?.filter((i) => i.enforce !== "pre");
|
|
321
|
-
if (nonPreTransformers?.length) {
|
|
322
|
-
console.warn(
|
|
323
|
-
// eslint-disable-next-line prefer-template
|
|
324
|
-
'[unocss] webpack integration only supports "pre" enforce transformers currently.the following transformers will be ignored\n' + nonPreTransformers.map((i) => ` - ${i.name}`).join("\n")
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
330
|
tasks.push(setupContentExtractor(ctx, typeof configOrPath === "object" && configOrPath?.watch));
|
|
328
331
|
const entries = /* @__PURE__ */ new Set();
|
|
329
332
|
const hashes = /* @__PURE__ */ new Map();
|
|
@@ -370,6 +373,13 @@ function unplugin(configOrPath, defaults) {
|
|
|
370
373
|
webpack(compiler) {
|
|
371
374
|
compiler.hooks.beforeCompile.tapPromise(PLUGIN_NAME, async () => {
|
|
372
375
|
await ctx.ready;
|
|
376
|
+
const nonPreTransformers = ctx.uno.config.transformers?.filter((i) => i.enforce !== "pre");
|
|
377
|
+
if (nonPreTransformers?.length) {
|
|
378
|
+
console.warn(
|
|
379
|
+
// eslint-disable-next-line prefer-template
|
|
380
|
+
'[unocss] webpack integration only supports "pre" enforce transformers currently.the following transformers will be ignored\n' + nonPreTransformers.map((i) => ` - ${i.name}`).join("\n")
|
|
381
|
+
);
|
|
382
|
+
}
|
|
373
383
|
});
|
|
374
384
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
375
385
|
const optimizeAssetsHook = (
|
|
@@ -378,9 +388,10 @@ function unplugin(configOrPath, defaults) {
|
|
|
378
388
|
compilation.hooks.optimizeAssets
|
|
379
389
|
);
|
|
380
390
|
optimizeAssetsHook.tapPromise(PLUGIN_NAME, async () => {
|
|
391
|
+
await ctx.ready;
|
|
381
392
|
const files = Object.keys(compilation.assets);
|
|
382
393
|
await flushTasks();
|
|
383
|
-
const result = await uno.generate(tokens, { minify: true });
|
|
394
|
+
const result = await ctx.uno.generate(tokens, { minify: true });
|
|
384
395
|
for (const file of files) {
|
|
385
396
|
if (file === "*")
|
|
386
397
|
return;
|
|
@@ -409,7 +420,7 @@ function unplugin(configOrPath, defaults) {
|
|
|
409
420
|
if (!plugin.__vfsModules)
|
|
410
421
|
return;
|
|
411
422
|
await flushTasks();
|
|
412
|
-
const result = await uno.generate(tokens);
|
|
423
|
+
const result = await ctx.uno.generate(tokens);
|
|
413
424
|
if (lastTokenSize === tokens.size)
|
|
414
425
|
return;
|
|
415
426
|
lastTokenSize = tokens.size;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/webpack",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.65.0-beta.1",
|
|
5
5
|
"description": "The Webpack plugin for UnoCSS",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"tinyglobby": "^0.2.10",
|
|
60
60
|
"unplugin": "^1.15.0",
|
|
61
61
|
"webpack-sources": "^3.2.3",
|
|
62
|
-
"@unocss/
|
|
63
|
-
"@unocss/
|
|
62
|
+
"@unocss/core": "0.65.0-beta.1",
|
|
63
|
+
"@unocss/config": "0.65.0-beta.1"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@types/webpack": "^5.28.5",
|