@unocss/vite 0.31.8 → 0.31.12

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
@@ -54,16 +54,16 @@ const CSS_PLACEHOLDER = "@unocss-placeholder";
54
54
 
55
55
  function createContext(configOrPath, defaults = {}, extraConfigSources = [], resolveConfigResult = () => {
56
56
  }) {
57
- const loadConfig = config.createConfigLoader(configOrPath, extraConfigSources);
57
+ let root = process.cwd();
58
58
  let rawConfig = {};
59
59
  const uno = core.createGenerator(rawConfig, defaults);
60
60
  let rollupFilter = pluginutils.createFilter(defaultInclude, defaultExclude);
61
61
  const invalidations = [];
62
62
  const modules = new core.BetterMap();
63
63
  const tokens = /* @__PURE__ */ new Set();
64
- const ready = reloadConfig();
64
+ let ready = reloadConfig();
65
65
  async function reloadConfig() {
66
- const result = await loadConfig();
66
+ const result = await config.loadConfig(root, configOrPath, extraConfigSources);
67
67
  resolveConfigResult(result);
68
68
  rawConfig = result.config;
69
69
  uno.setConfig(rawConfig);
@@ -74,6 +74,13 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
74
74
  invalidate();
75
75
  return result;
76
76
  }
77
+ async function updateRoot(newRoot) {
78
+ if (newRoot !== root) {
79
+ root = newRoot;
80
+ ready = reloadConfig();
81
+ }
82
+ return await ready;
83
+ }
77
84
  function invalidate() {
78
85
  invalidations.forEach((cb) => cb());
79
86
  }
@@ -93,7 +100,9 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
93
100
  return rawConfig;
94
101
  }
95
102
  return {
96
- ready,
103
+ get ready() {
104
+ return ready;
105
+ },
97
106
  tokens,
98
107
  modules,
99
108
  invalidate,
@@ -104,7 +113,9 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
104
113
  reloadConfig,
105
114
  uno,
106
115
  extract,
107
- getConfig
116
+ getConfig,
117
+ root,
118
+ updateRoot
108
119
  };
109
120
  }
110
121
 
@@ -258,6 +269,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
258
269
  let base = "";
259
270
  const tasks = [];
260
271
  const entries = /* @__PURE__ */ new Map();
272
+ const cssModules = /* @__PURE__ */ new Set();
261
273
  let invalidateTimer;
262
274
  let lastUpdate = Date.now();
263
275
  let lastServed = 0;
@@ -271,8 +283,12 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
271
283
  base = base.slice(0, base.length - 1);
272
284
  }
273
285
  function invalidate(timer = 10) {
286
+ const ids = [
287
+ ...entries.keys(),
288
+ ...cssModules.keys()
289
+ ];
274
290
  for (const server of servers) {
275
- for (const id of entries.keys()) {
291
+ for (const id of ids) {
276
292
  const mod = server.moduleGraph.getModuleById(id);
277
293
  if (!mod)
278
294
  continue;
@@ -284,10 +300,14 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
284
300
  }
285
301
  function sendUpdate() {
286
302
  lastUpdate = Date.now();
303
+ const ids = [
304
+ ...entries.keys(),
305
+ ...cssModules.keys()
306
+ ];
287
307
  for (const server of servers) {
288
308
  server.ws.send({
289
309
  type: "update",
290
- updates: Array.from(entries.keys()).map((i) => ({
310
+ updates: Array.from(ids).map((i) => ({
291
311
  acceptedPath: i,
292
312
  path: i,
293
313
  timestamp: lastUpdate,
@@ -348,6 +368,8 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
348
368
  entries.set(entry.id, entry.layer);
349
369
  return entry.id;
350
370
  }
371
+ if (id.match(regexCssId))
372
+ cssModules.add(id);
351
373
  },
352
374
  async load(id) {
353
375
  const layer = entries.get(getPath(id));
@@ -610,8 +632,8 @@ function ConfigHMRPlugin(ctx) {
610
632
  const { ready, uno } = ctx;
611
633
  return {
612
634
  name: "unocss:config",
613
- async configResolved() {
614
- await ready;
635
+ async configResolved(config) {
636
+ await ctx.updateRoot(config.root);
615
637
  },
616
638
  async configureServer(server) {
617
639
  uno.config.envMode = "dev";
@@ -822,9 +844,9 @@ function UnocssPlugin(configOrPath, defaults = {}) {
822
844
  const inlineConfig = configOrPath && typeof configOrPath !== "string" ? configOrPath : {};
823
845
  const mode = inlineConfig.mode ?? "global";
824
846
  const plugins = [
847
+ ConfigHMRPlugin(ctx),
825
848
  ...initTransformerPlugins(ctx),
826
- ...createDevtoolsPlugin(ctx),
827
- ConfigHMRPlugin(ctx)
849
+ ...createDevtoolsPlugin(ctx)
828
850
  ];
829
851
  if (inlineConfig.inspector !== false)
830
852
  plugins.push(UnocssInspector__default(ctx));
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import UnocssInspector from '@unocss/inspector';
2
2
  import { createFilter } from '@rollup/pluginutils';
3
- import { createConfigLoader } from '@unocss/config';
3
+ import { loadConfig } from '@unocss/config';
4
4
  import { createGenerator, BetterMap, toEscapedSelector } from '@unocss/core';
5
5
  import { createHash } from 'crypto';
6
6
  import MagicString from 'magic-string';
@@ -44,16 +44,16 @@ const CSS_PLACEHOLDER = "@unocss-placeholder";
44
44
 
45
45
  function createContext(configOrPath, defaults = {}, extraConfigSources = [], resolveConfigResult = () => {
46
46
  }) {
47
- const loadConfig = createConfigLoader(configOrPath, extraConfigSources);
47
+ let root = process.cwd();
48
48
  let rawConfig = {};
49
49
  const uno = createGenerator(rawConfig, defaults);
50
50
  let rollupFilter = createFilter(defaultInclude, defaultExclude);
51
51
  const invalidations = [];
52
52
  const modules = new BetterMap();
53
53
  const tokens = /* @__PURE__ */ new Set();
54
- const ready = reloadConfig();
54
+ let ready = reloadConfig();
55
55
  async function reloadConfig() {
56
- const result = await loadConfig();
56
+ const result = await loadConfig(root, configOrPath, extraConfigSources);
57
57
  resolveConfigResult(result);
58
58
  rawConfig = result.config;
59
59
  uno.setConfig(rawConfig);
@@ -64,6 +64,13 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
64
64
  invalidate();
65
65
  return result;
66
66
  }
67
+ async function updateRoot(newRoot) {
68
+ if (newRoot !== root) {
69
+ root = newRoot;
70
+ ready = reloadConfig();
71
+ }
72
+ return await ready;
73
+ }
67
74
  function invalidate() {
68
75
  invalidations.forEach((cb) => cb());
69
76
  }
@@ -83,7 +90,9 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
83
90
  return rawConfig;
84
91
  }
85
92
  return {
86
- ready,
93
+ get ready() {
94
+ return ready;
95
+ },
87
96
  tokens,
88
97
  modules,
89
98
  invalidate,
@@ -94,7 +103,9 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
94
103
  reloadConfig,
95
104
  uno,
96
105
  extract,
97
- getConfig
106
+ getConfig,
107
+ root,
108
+ updateRoot
98
109
  };
99
110
  }
100
111
 
@@ -248,6 +259,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
248
259
  let base = "";
249
260
  const tasks = [];
250
261
  const entries = /* @__PURE__ */ new Map();
262
+ const cssModules = /* @__PURE__ */ new Set();
251
263
  let invalidateTimer;
252
264
  let lastUpdate = Date.now();
253
265
  let lastServed = 0;
@@ -261,8 +273,12 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
261
273
  base = base.slice(0, base.length - 1);
262
274
  }
263
275
  function invalidate(timer = 10) {
276
+ const ids = [
277
+ ...entries.keys(),
278
+ ...cssModules.keys()
279
+ ];
264
280
  for (const server of servers) {
265
- for (const id of entries.keys()) {
281
+ for (const id of ids) {
266
282
  const mod = server.moduleGraph.getModuleById(id);
267
283
  if (!mod)
268
284
  continue;
@@ -274,10 +290,14 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
274
290
  }
275
291
  function sendUpdate() {
276
292
  lastUpdate = Date.now();
293
+ const ids = [
294
+ ...entries.keys(),
295
+ ...cssModules.keys()
296
+ ];
277
297
  for (const server of servers) {
278
298
  server.ws.send({
279
299
  type: "update",
280
- updates: Array.from(entries.keys()).map((i) => ({
300
+ updates: Array.from(ids).map((i) => ({
281
301
  acceptedPath: i,
282
302
  path: i,
283
303
  timestamp: lastUpdate,
@@ -338,6 +358,8 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
338
358
  entries.set(entry.id, entry.layer);
339
359
  return entry.id;
340
360
  }
361
+ if (id.match(regexCssId))
362
+ cssModules.add(id);
341
363
  },
342
364
  async load(id) {
343
365
  const layer = entries.get(getPath(id));
@@ -600,8 +622,8 @@ function ConfigHMRPlugin(ctx) {
600
622
  const { ready, uno } = ctx;
601
623
  return {
602
624
  name: "unocss:config",
603
- async configResolved() {
604
- await ready;
625
+ async configResolved(config) {
626
+ await ctx.updateRoot(config.root);
605
627
  },
606
628
  async configureServer(server) {
607
629
  uno.config.envMode = "dev";
@@ -812,9 +834,9 @@ function UnocssPlugin(configOrPath, defaults = {}) {
812
834
  const inlineConfig = configOrPath && typeof configOrPath !== "string" ? configOrPath : {};
813
835
  const mode = inlineConfig.mode ?? "global";
814
836
  const plugins = [
837
+ ConfigHMRPlugin(ctx),
815
838
  ...initTransformerPlugins(ctx),
816
- ...createDevtoolsPlugin(ctx),
817
- ConfigHMRPlugin(ctx)
839
+ ...createDevtoolsPlugin(ctx)
818
840
  ];
819
841
  if (inlineConfig.inspector !== false)
820
842
  plugins.push(UnocssInspector(ctx));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.31.8",
3
+ "version": "0.31.12",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "keywords": [
6
6
  "unocss",
@@ -43,11 +43,11 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@rollup/pluginutils": "^4.2.1",
46
- "@unocss/config": "0.31.8",
47
- "@unocss/core": "0.31.8",
48
- "@unocss/inspector": "0.31.8",
49
- "@unocss/scope": "0.31.8",
50
- "@unocss/transformer-directives": "0.31.8",
46
+ "@unocss/config": "0.31.12",
47
+ "@unocss/core": "0.31.12",
48
+ "@unocss/inspector": "0.31.12",
49
+ "@unocss/scope": "0.31.12",
50
+ "@unocss/transformer-directives": "0.31.12",
51
51
  "magic-string": "^0.26.1"
52
52
  },
53
53
  "devDependencies": {