@unocss/vite 0.12.12 → 0.12.16

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.js CHANGED
@@ -76,6 +76,7 @@ var import_config = __toModule(require("@unocss/config"));
76
76
  var import_core = __toModule(require("@unocss/core"));
77
77
  function createContext(configOrPath, defaults = {}) {
78
78
  const { config = {}, filepath } = (0, import_config.loadConfig)(configOrPath);
79
+ let rawConfig = config;
79
80
  const uno = (0, import_core.createGenerator)(config, defaults);
80
81
  const invalidations = [];
81
82
  const modules = new import_core.BetterMap();
@@ -84,16 +85,19 @@ function createContext(configOrPath, defaults = {}) {
84
85
  function invalidate() {
85
86
  invalidations.forEach((cb) => cb());
86
87
  }
87
- async function scan(code, id) {
88
+ async function extract(code, id) {
88
89
  if (id)
89
90
  modules.set(id, code);
91
+ const len = tokens.size;
90
92
  await uno.applyExtractors(code, id, tokens);
91
- invalidate();
93
+ if (tokens.size > len)
94
+ invalidate();
92
95
  }
93
96
  async function reloadConfig() {
94
97
  if (!filepath)
95
98
  return;
96
- uno.setConfig((0, import_config.loadConfig)(filepath).config);
99
+ rawConfig = (0, import_config.loadConfig)(filepath).config;
100
+ uno.setConfig(rawConfig);
97
101
  uno.config.envMode = "dev";
98
102
  rollupFilter = (0, import_pluginutils.createFilter)(config.include || defaultInclude, config.exclude || defaultExclude);
99
103
  tokens.clear();
@@ -113,8 +117,10 @@ function createContext(configOrPath, defaults = {}) {
113
117
  filter,
114
118
  reloadConfig,
115
119
  uno,
116
- extract: scan,
117
- config,
120
+ extract,
121
+ get config() {
122
+ return rawConfig;
123
+ },
118
124
  configFilepath: filepath
119
125
  };
120
126
  }
@@ -286,7 +292,6 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
286
292
  const mod = server.moduleGraph.getModuleById(id);
287
293
  if (!mod)
288
294
  continue;
289
- lastUpdate = Date.now();
290
295
  server.moduleGraph.invalidateModule(mod);
291
296
  }
292
297
  }
@@ -294,6 +299,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
294
299
  invalidateTimer = setTimeout(sendUpdate, timer);
295
300
  }
296
301
  function sendUpdate() {
302
+ lastUpdate = Date.now();
297
303
  for (const server of servers) {
298
304
  server.ws.send({
299
305
  type: "update",
@@ -491,9 +497,16 @@ function VueScopedPlugin({ uno, config }) {
491
497
  }
492
498
 
493
499
  // src/config-hmr.ts
494
- function ConfigHMRPlugin({ uno, configFilepath, reloadConfig }) {
500
+ function ConfigHMRPlugin(ctx) {
501
+ const { uno, configFilepath, reloadConfig } = ctx;
495
502
  return {
496
503
  name: "unocss:config",
504
+ api: {
505
+ get config() {
506
+ if (!configFilepath)
507
+ return ctx.config;
508
+ }
509
+ },
497
510
  configureServer(server) {
498
511
  uno.config.envMode = "dev";
499
512
  if (!configFilepath)
package/dist/index.mjs CHANGED
@@ -42,6 +42,7 @@ import { loadConfig } from "@unocss/config";
42
42
  import { BetterMap, createGenerator } from "@unocss/core";
43
43
  function createContext(configOrPath, defaults = {}) {
44
44
  const { config = {}, filepath } = loadConfig(configOrPath);
45
+ let rawConfig = config;
45
46
  const uno = createGenerator(config, defaults);
46
47
  const invalidations = [];
47
48
  const modules = new BetterMap();
@@ -50,16 +51,19 @@ function createContext(configOrPath, defaults = {}) {
50
51
  function invalidate() {
51
52
  invalidations.forEach((cb) => cb());
52
53
  }
53
- async function scan(code, id) {
54
+ async function extract(code, id) {
54
55
  if (id)
55
56
  modules.set(id, code);
57
+ const len = tokens.size;
56
58
  await uno.applyExtractors(code, id, tokens);
57
- invalidate();
59
+ if (tokens.size > len)
60
+ invalidate();
58
61
  }
59
62
  async function reloadConfig() {
60
63
  if (!filepath)
61
64
  return;
62
- uno.setConfig(loadConfig(filepath).config);
65
+ rawConfig = loadConfig(filepath).config;
66
+ uno.setConfig(rawConfig);
63
67
  uno.config.envMode = "dev";
64
68
  rollupFilter = createFilter(config.include || defaultInclude, config.exclude || defaultExclude);
65
69
  tokens.clear();
@@ -79,8 +83,10 @@ function createContext(configOrPath, defaults = {}) {
79
83
  filter,
80
84
  reloadConfig,
81
85
  uno,
82
- extract: scan,
83
- config,
86
+ extract,
87
+ get config() {
88
+ return rawConfig;
89
+ },
84
90
  configFilepath: filepath
85
91
  };
86
92
  }
@@ -252,7 +258,6 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
252
258
  const mod = server.moduleGraph.getModuleById(id);
253
259
  if (!mod)
254
260
  continue;
255
- lastUpdate = Date.now();
256
261
  server.moduleGraph.invalidateModule(mod);
257
262
  }
258
263
  }
@@ -260,6 +265,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
260
265
  invalidateTimer = setTimeout(sendUpdate, timer);
261
266
  }
262
267
  function sendUpdate() {
268
+ lastUpdate = Date.now();
263
269
  for (const server of servers) {
264
270
  server.ws.send({
265
271
  type: "update",
@@ -457,9 +463,16 @@ function VueScopedPlugin({ uno, config }) {
457
463
  }
458
464
 
459
465
  // src/config-hmr.ts
460
- function ConfigHMRPlugin({ uno, configFilepath, reloadConfig }) {
466
+ function ConfigHMRPlugin(ctx) {
467
+ const { uno, configFilepath, reloadConfig } = ctx;
461
468
  return {
462
469
  name: "unocss:config",
470
+ api: {
471
+ get config() {
472
+ if (!configFilepath)
473
+ return ctx.config;
474
+ }
475
+ },
463
476
  configureServer(server) {
464
477
  uno.config.envMode = "dev";
465
478
  if (!configFilepath)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.12.12",
3
+ "version": "0.12.16",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "keywords": [
6
6
  "unocss",
@@ -35,10 +35,10 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@rollup/pluginutils": "^4.1.1",
38
- "@unocss/config": "0.12.12",
39
- "@unocss/core": "0.12.12",
40
- "@unocss/inspector": "0.12.12",
41
- "@unocss/scope": "0.12.12"
38
+ "@unocss/config": "0.12.16",
39
+ "@unocss/core": "0.12.16",
40
+ "@unocss/inspector": "0.12.16",
41
+ "@unocss/scope": "0.12.16"
42
42
  },
43
43
  "devDependencies": {
44
44
  "vite": "^2.6.14"