@unocss/vite 0.57.6 → 0.58.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
@@ -92,7 +92,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
92
92
  let rawConfig = {};
93
93
  let configFileList = [];
94
94
  const uno = core.createGenerator(rawConfig, defaults);
95
- let rollupFilter = pluginutils.createFilter(defaultPipelineInclude, defaultPipelineExclude);
95
+ let rollupFilter = pluginutils.createFilter(
96
+ defaultPipelineInclude,
97
+ defaultPipelineExclude,
98
+ { resolve: typeof configOrPath === "string" ? configOrPath : root }
99
+ );
96
100
  const invalidations = [];
97
101
  const reloadListeners = [];
98
102
  const modules = new core.BetterMap();
@@ -110,7 +114,8 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
110
114
  uno.config.envMode = "dev";
111
115
  rollupFilter = rawConfig.content?.pipeline === false ? () => false : pluginutils.createFilter(
112
116
  rawConfig.content?.pipeline?.include || rawConfig.include || defaultPipelineInclude,
113
- rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude
117
+ rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude,
118
+ { resolve: typeof configOrPath === "string" ? configOrPath : root }
114
119
  );
115
120
  tokens.clear();
116
121
  await Promise.all(modules.map((code, id) => uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens)));
@@ -426,6 +431,11 @@ function GlobalModeBuildPlugin(ctx) {
426
431
  order: "pre",
427
432
  handler(code, { filename }) {
428
433
  tasks.push(extract(code, filename));
434
+ },
435
+ // Compatibility with Legacy Vite
436
+ enforce: "pre",
437
+ transform(code, { filename }) {
438
+ tasks.push(extract(code, filename));
429
439
  }
430
440
  },
431
441
  resolveId(id, importer) {
@@ -482,7 +492,7 @@ function GlobalModeBuildPlugin(ctx) {
482
492
  async renderChunk(_, chunk, options) {
483
493
  if (isLegacyChunk(chunk, options))
484
494
  return null;
485
- if (!Object.keys(chunk.modules).some((i) => i.match(RESOLVED_ID_RE)))
495
+ if (!Object.keys(chunk.modules).some((i) => RESOLVED_ID_RE.test(i)))
486
496
  return null;
487
497
  const cssPost = cssPostPlugins.get(options.dir);
488
498
  if (!cssPost) {
@@ -521,7 +531,7 @@ function GlobalModeBuildPlugin(ctx) {
521
531
  async renderChunk(code, chunk, options) {
522
532
  if (isLegacyChunk(chunk, options))
523
533
  return null;
524
- if (!Object.keys(chunk.modules).some((i) => i.match(RESOLVED_ID_RE)))
534
+ if (!Object.keys(chunk.modules).some((i) => RESOLVED_ID_RE.test(i)))
525
535
  return null;
526
536
  const cssPost = cssPostPlugins.get(options.dir);
527
537
  if (!cssPost) {
@@ -711,6 +721,12 @@ function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules,
711
721
  handler(code, { filename }) {
712
722
  setWarnTimer();
713
723
  tasks.push(extract(code, filename));
724
+ },
725
+ // Compatibility with Legacy Vite
726
+ enforce: "pre",
727
+ transform(code, { filename }) {
728
+ setWarnTimer();
729
+ tasks.push(extract(code, filename));
714
730
  }
715
731
  },
716
732
  resolveId(id) {
@@ -832,7 +848,7 @@ function PerModuleModePlugin({ uno, filter }) {
832
848
  if (!filter(code, id))
833
849
  return;
834
850
  const hash = getHash(id);
835
- const hasScope = code.match(SCOPE_IMPORT_RE);
851
+ const hasScope = SCOPE_IMPORT_RE.test(code);
836
852
  const { css } = await uno.generate(code, { id, scope: hasScope ? `.${hash}` : void 0, preflights: false });
837
853
  if (!css && !hasScope)
838
854
  return null;
@@ -1044,20 +1060,27 @@ function ConfigHMRPlugin(ctx) {
1044
1060
  }
1045
1061
 
1046
1062
  function createTransformerPlugins(ctx) {
1047
- const enforces = ["default", "pre", "post"];
1048
- return enforces.map((enforce) => ({
1049
- name: `unocss:transformers:${enforce}`,
1050
- enforce: enforce === "default" ? void 0 : enforce,
1051
- transform(code, id) {
1052
- return applyTransformers(ctx, code, id, enforce);
1053
- },
1054
- transformIndexHtml: {
1055
- order: enforce === "default" ? void 0 : enforce,
1056
- handler(code) {
1057
- return applyTransformers(ctx, code, "index.html", enforce).then((t) => t?.code);
1063
+ const orders = ["default", "pre", "post"];
1064
+ return orders.map((_order) => {
1065
+ const order = _order === "default" ? void 0 : _order;
1066
+ const htmlHandler = (code) => {
1067
+ return applyTransformers(ctx, code, "index.html", order).then((t) => t?.code);
1068
+ };
1069
+ return {
1070
+ name: `unocss:transformers:${order}`,
1071
+ enforce: order,
1072
+ transform(code, id) {
1073
+ return applyTransformers(ctx, code, id, order);
1074
+ },
1075
+ transformIndexHtml: {
1076
+ order,
1077
+ handler: htmlHandler,
1078
+ // Compatibility with Legacy Vite
1079
+ enforce: order,
1080
+ transform: htmlHandler
1058
1081
  }
1059
- }
1060
- }));
1082
+ };
1083
+ });
1061
1084
  }
1062
1085
 
1063
1086
  const _dirname = typeof __dirname !== "undefined" ? __dirname : node_path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
package/dist/index.mjs CHANGED
@@ -77,7 +77,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
77
77
  let rawConfig = {};
78
78
  let configFileList = [];
79
79
  const uno = createGenerator(rawConfig, defaults);
80
- let rollupFilter = createFilter(defaultPipelineInclude, defaultPipelineExclude);
80
+ let rollupFilter = createFilter(
81
+ defaultPipelineInclude,
82
+ defaultPipelineExclude,
83
+ { resolve: typeof configOrPath === "string" ? configOrPath : root }
84
+ );
81
85
  const invalidations = [];
82
86
  const reloadListeners = [];
83
87
  const modules = new BetterMap();
@@ -95,7 +99,8 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
95
99
  uno.config.envMode = "dev";
96
100
  rollupFilter = rawConfig.content?.pipeline === false ? () => false : createFilter(
97
101
  rawConfig.content?.pipeline?.include || rawConfig.include || defaultPipelineInclude,
98
- rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude
102
+ rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude,
103
+ { resolve: typeof configOrPath === "string" ? configOrPath : root }
99
104
  );
100
105
  tokens.clear();
101
106
  await Promise.all(modules.map((code, id) => uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens)));
@@ -411,6 +416,11 @@ function GlobalModeBuildPlugin(ctx) {
411
416
  order: "pre",
412
417
  handler(code, { filename }) {
413
418
  tasks.push(extract(code, filename));
419
+ },
420
+ // Compatibility with Legacy Vite
421
+ enforce: "pre",
422
+ transform(code, { filename }) {
423
+ tasks.push(extract(code, filename));
414
424
  }
415
425
  },
416
426
  resolveId(id, importer) {
@@ -467,7 +477,7 @@ function GlobalModeBuildPlugin(ctx) {
467
477
  async renderChunk(_, chunk, options) {
468
478
  if (isLegacyChunk(chunk, options))
469
479
  return null;
470
- if (!Object.keys(chunk.modules).some((i) => i.match(RESOLVED_ID_RE)))
480
+ if (!Object.keys(chunk.modules).some((i) => RESOLVED_ID_RE.test(i)))
471
481
  return null;
472
482
  const cssPost = cssPostPlugins.get(options.dir);
473
483
  if (!cssPost) {
@@ -506,7 +516,7 @@ function GlobalModeBuildPlugin(ctx) {
506
516
  async renderChunk(code, chunk, options) {
507
517
  if (isLegacyChunk(chunk, options))
508
518
  return null;
509
- if (!Object.keys(chunk.modules).some((i) => i.match(RESOLVED_ID_RE)))
519
+ if (!Object.keys(chunk.modules).some((i) => RESOLVED_ID_RE.test(i)))
510
520
  return null;
511
521
  const cssPost = cssPostPlugins.get(options.dir);
512
522
  if (!cssPost) {
@@ -696,6 +706,12 @@ function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules,
696
706
  handler(code, { filename }) {
697
707
  setWarnTimer();
698
708
  tasks.push(extract(code, filename));
709
+ },
710
+ // Compatibility with Legacy Vite
711
+ enforce: "pre",
712
+ transform(code, { filename }) {
713
+ setWarnTimer();
714
+ tasks.push(extract(code, filename));
699
715
  }
700
716
  },
701
717
  resolveId(id) {
@@ -817,7 +833,7 @@ function PerModuleModePlugin({ uno, filter }) {
817
833
  if (!filter(code, id))
818
834
  return;
819
835
  const hash = getHash(id);
820
- const hasScope = code.match(SCOPE_IMPORT_RE);
836
+ const hasScope = SCOPE_IMPORT_RE.test(code);
821
837
  const { css } = await uno.generate(code, { id, scope: hasScope ? `.${hash}` : void 0, preflights: false });
822
838
  if (!css && !hasScope)
823
839
  return null;
@@ -1029,20 +1045,27 @@ function ConfigHMRPlugin(ctx) {
1029
1045
  }
1030
1046
 
1031
1047
  function createTransformerPlugins(ctx) {
1032
- const enforces = ["default", "pre", "post"];
1033
- return enforces.map((enforce) => ({
1034
- name: `unocss:transformers:${enforce}`,
1035
- enforce: enforce === "default" ? void 0 : enforce,
1036
- transform(code, id) {
1037
- return applyTransformers(ctx, code, id, enforce);
1038
- },
1039
- transformIndexHtml: {
1040
- order: enforce === "default" ? void 0 : enforce,
1041
- handler(code) {
1042
- return applyTransformers(ctx, code, "index.html", enforce).then((t) => t?.code);
1048
+ const orders = ["default", "pre", "post"];
1049
+ return orders.map((_order) => {
1050
+ const order = _order === "default" ? void 0 : _order;
1051
+ const htmlHandler = (code) => {
1052
+ return applyTransformers(ctx, code, "index.html", order).then((t) => t?.code);
1053
+ };
1054
+ return {
1055
+ name: `unocss:transformers:${order}`,
1056
+ enforce: order,
1057
+ transform(code, id) {
1058
+ return applyTransformers(ctx, code, id, order);
1059
+ },
1060
+ transformIndexHtml: {
1061
+ order,
1062
+ handler: htmlHandler,
1063
+ // Compatibility with Legacy Vite
1064
+ enforce: order,
1065
+ transform: htmlHandler
1043
1066
  }
1044
- }
1045
- }));
1067
+ };
1068
+ });
1046
1069
  }
1047
1070
 
1048
1071
  const _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.57.6",
3
+ "version": "0.58.0",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -43,19 +43,19 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@ampproject/remapping": "^2.2.1",
46
- "@rollup/pluginutils": "^5.0.5",
46
+ "@rollup/pluginutils": "^5.1.0",
47
47
  "chokidar": "^3.5.3",
48
48
  "fast-glob": "^3.3.2",
49
49
  "magic-string": "^0.30.5",
50
- "@unocss/config": "0.57.6",
51
- "@unocss/core": "0.57.6",
52
- "@unocss/inspector": "0.57.6",
53
- "@unocss/scope": "0.57.6",
54
- "@unocss/transformer-directives": "0.57.6"
50
+ "@unocss/config": "0.58.0",
51
+ "@unocss/core": "0.58.0",
52
+ "@unocss/inspector": "0.58.0",
53
+ "@unocss/scope": "0.58.0",
54
+ "@unocss/transformer-directives": "0.58.0"
55
55
  },
56
56
  "devDependencies": {
57
- "vite": "^5.0.0",
58
- "@unocss/shared-integration": "0.57.6"
57
+ "vite": "^5.0.4",
58
+ "@unocss/shared-integration": "0.58.0"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "unbuild",