@unocss/vite 0.33.4 → 0.33.5

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
@@ -195,6 +195,7 @@ function ChunkModeBuildPlugin({ uno, filter }) {
195
195
 
196
196
  function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, getConfig }) {
197
197
  const vfsLayerMap = /* @__PURE__ */ new Map();
198
+ const layerImporterMap = /* @__PURE__ */ new Map();
198
199
  let tasks = [];
199
200
  let cssPostPlugin;
200
201
  let cssPlugin;
@@ -233,10 +234,12 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
233
234
  tasks.push(extract(code, filename));
234
235
  }
235
236
  },
236
- resolveId(id) {
237
+ resolveId(id, importer) {
237
238
  const entry = resolveId(id);
238
239
  if (entry) {
239
240
  vfsLayerMap.set(entry.id, entry.layer);
241
+ if (importer)
242
+ layerImporterMap.set(importer, entry.id);
240
243
  return entry.id;
241
244
  }
242
245
  },
@@ -245,6 +248,15 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
245
248
  if (layer)
246
249
  return getLayerPlaceholder(layer);
247
250
  },
251
+ moduleParsed({ id, importedIds }) {
252
+ if (!layerImporterMap.has(id))
253
+ return;
254
+ const layerKey = layerImporterMap.get(id);
255
+ if (!importedIds.includes(layerKey)) {
256
+ layerImporterMap.delete(id);
257
+ vfsLayerMap.delete(layerKey);
258
+ }
259
+ },
248
260
  async configResolved(config) {
249
261
  cssPostPlugin = config.plugins.find((i) => i.name === "vite:css-post");
250
262
  cssPlugin = config.plugins.find((i) => i.name === "vite:css");
@@ -284,15 +296,15 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
284
296
  },
285
297
  enforce: "post",
286
298
  async generateBundle(_, bundle) {
299
+ const files = Object.keys(bundle);
300
+ const cssFiles = files.filter((i) => i.endsWith(".css"));
301
+ if (!cssFiles.length)
302
+ return;
287
303
  if (!vfsLayerMap.size) {
288
304
  const msg = "[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?";
289
305
  this.warn(msg);
290
306
  return;
291
307
  }
292
- const files = Object.keys(bundle);
293
- const cssFiles = files.filter((i) => i.endsWith(".css"));
294
- if (!cssFiles.length)
295
- return;
296
308
  await Promise.all(tasks);
297
309
  const result = await uno.generate(tokens, { minify: true });
298
310
  let replaced = false;
package/dist/index.d.ts CHANGED
@@ -52,6 +52,6 @@ declare function VueScopedPlugin({ uno, ready }: UnocssPluginContext): Plugin;
52
52
  declare function SvelteScopedPlugin({ uno, ready }: UnocssPluginContext): Plugin;
53
53
 
54
54
  declare function defineConfig<Theme extends {}>(config: VitePluginConfig<Theme>): VitePluginConfig<Theme>;
55
- declare function UnocssPlugin(configOrPath?: VitePluginConfig | string, defaults?: UserConfigDefaults): Plugin[];
55
+ declare function UnocssPlugin<Theme extends {}>(configOrPath?: VitePluginConfig<Theme> | string, defaults?: UserConfigDefaults): Plugin[];
56
56
 
57
57
  export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, SvelteScopedPlugin, VitePluginConfig, VueScopedPlugin, UnocssPlugin as default, defineConfig };
package/dist/index.mjs CHANGED
@@ -185,6 +185,7 @@ function ChunkModeBuildPlugin({ uno, filter }) {
185
185
 
186
186
  function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, getConfig }) {
187
187
  const vfsLayerMap = /* @__PURE__ */ new Map();
188
+ const layerImporterMap = /* @__PURE__ */ new Map();
188
189
  let tasks = [];
189
190
  let cssPostPlugin;
190
191
  let cssPlugin;
@@ -223,10 +224,12 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
223
224
  tasks.push(extract(code, filename));
224
225
  }
225
226
  },
226
- resolveId(id) {
227
+ resolveId(id, importer) {
227
228
  const entry = resolveId(id);
228
229
  if (entry) {
229
230
  vfsLayerMap.set(entry.id, entry.layer);
231
+ if (importer)
232
+ layerImporterMap.set(importer, entry.id);
230
233
  return entry.id;
231
234
  }
232
235
  },
@@ -235,6 +238,15 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
235
238
  if (layer)
236
239
  return getLayerPlaceholder(layer);
237
240
  },
241
+ moduleParsed({ id, importedIds }) {
242
+ if (!layerImporterMap.has(id))
243
+ return;
244
+ const layerKey = layerImporterMap.get(id);
245
+ if (!importedIds.includes(layerKey)) {
246
+ layerImporterMap.delete(id);
247
+ vfsLayerMap.delete(layerKey);
248
+ }
249
+ },
238
250
  async configResolved(config) {
239
251
  cssPostPlugin = config.plugins.find((i) => i.name === "vite:css-post");
240
252
  cssPlugin = config.plugins.find((i) => i.name === "vite:css");
@@ -274,15 +286,15 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
274
286
  },
275
287
  enforce: "post",
276
288
  async generateBundle(_, bundle) {
289
+ const files = Object.keys(bundle);
290
+ const cssFiles = files.filter((i) => i.endsWith(".css"));
291
+ if (!cssFiles.length)
292
+ return;
277
293
  if (!vfsLayerMap.size) {
278
294
  const msg = "[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?";
279
295
  this.warn(msg);
280
296
  return;
281
297
  }
282
- const files = Object.keys(bundle);
283
- const cssFiles = files.filter((i) => i.endsWith(".css"));
284
- if (!cssFiles.length)
285
- return;
286
298
  await Promise.all(tasks);
287
299
  const result = await uno.generate(tokens, { minify: true });
288
300
  let replaced = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.33.4",
3
+ "version": "0.33.5",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "keywords": [
6
6
  "unocss",
@@ -43,15 +43,15 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@rollup/pluginutils": "^4.2.1",
46
- "@unocss/config": "0.33.4",
47
- "@unocss/core": "0.33.4",
48
- "@unocss/inspector": "0.33.4",
49
- "@unocss/scope": "0.33.4",
50
- "@unocss/transformer-directives": "0.33.4",
46
+ "@unocss/config": "0.33.5",
47
+ "@unocss/core": "0.33.5",
48
+ "@unocss/inspector": "0.33.5",
49
+ "@unocss/scope": "0.33.5",
50
+ "@unocss/transformer-directives": "0.33.5",
51
51
  "magic-string": "^0.26.2"
52
52
  },
53
53
  "devDependencies": {
54
- "@unocss/shared-integration": "0.33.4",
54
+ "@unocss/shared-integration": "0.33.5",
55
55
  "vite": "^2.9.9"
56
56
  },
57
57
  "scripts": {