@unocss/vite 0.31.6 → 0.31.10

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