@unocss/vite 0.32.1 → 0.32.9

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
3
+ Copyright (c) 2021-PRESENT Anthony Fu <https://github.com/antfu>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -28,11 +28,33 @@ Add `uno.css` to your main entry:
28
28
  import 'uno.css'
29
29
  ```
30
30
 
31
+ ### Presetless usage
32
+
33
+ ```bash
34
+ npm i -D @unocss/vite
35
+ ```
36
+
37
+ ```ts
38
+ // vite.config.ts
39
+ import Unocss from '@unocss/vite'
40
+
41
+ export default {
42
+ plugins: [
43
+ Unocss({
44
+ presets: [
45
+ /* no presets by default */
46
+ ],
47
+ /* options */
48
+ }),
49
+ ],
50
+ }
51
+ ```
52
+
31
53
  ## Modes
32
54
 
33
55
  The Vite plugin comes with a set of modes that enable different behaviors.
34
56
 
35
- ### global (default)
57
+ ###### `global` (default)
36
58
 
37
59
  This is the default mode for the plugin: in this mode you need to add the import of `uno.css` on your entry point.
38
60
 
@@ -40,25 +62,25 @@ This mode enables a set of Vite plugins for `build` and for `dev` with `HMR` sup
40
62
 
41
63
  The generated `css` will be a global stylesheet injected on the `index.html`.
42
64
 
43
- ### vue-scoped
65
+ ###### `vue-scoped`
44
66
 
45
67
  This mode will inject generated CSS to Vue SFC's `<style scoped>` for isolation.
46
68
 
47
- ### svelte-scoped
69
+ ###### `svelte-scoped`
48
70
 
49
71
  This mode will inject generated CSS to Svelte's `<style>` for isolation.
50
72
 
51
- ### shadow-dom
73
+ ###### `shadow-dom`
52
74
 
53
75
  Since `Web Components` uses `Shadow DOM`, there is no way to style content directly from a global stylesheet (unless you use `custom css vars`, those will penetrate the `Shadow DOM`), you need to inline the generated css by the plugin into the `Shadow DOM` style.
54
76
 
55
77
  To inline the generated css, you only need to configure the plugin mode to `shadow-dom` and include `@unocss-placeholder` magic placeholder on each web component style css block.
56
78
 
57
- ### per-module (Experimental)
79
+ ###### `per-module` (Experimental)
58
80
 
59
81
  This mode will generate a CSS sheet for each module, can be scoped.
60
82
 
61
- ### dist-chunk (Experimental)
83
+ ###### `dist-chunk` (Experimental)
62
84
 
63
85
  This mode will generate a CSS sheet for each code chunk on build, great for MPA.
64
86
 
@@ -201,7 +223,7 @@ You must add the plugin before `@sveltejs/vite-plugin-svelte`.
201
223
 
202
224
  To support `class:foo` and `class:foo={bar}` add the plugin and configure `extractorSvelte` on `extractors` option.
203
225
 
204
- You can use simple rules with `class:`, for example `class:bg-red-500={foo}` or using `shorcuts` to include multiples rules, see `src/App.svelte` on linked example project bellow.
226
+ You can use simple rules with `class:`, for example `class:bg-red-500={foo}` or using `shorcuts` to include multiples rules, see `src/App.svelte` on linked example project below.
205
227
 
206
228
  ```ts
207
229
  // vite.config.js
@@ -226,7 +248,7 @@ You have a `Vite + Svelte` example project on [examples/vite-svelte](https://git
226
248
 
227
249
  To support `class:foo` and `class:foo={bar}` add the plugin and configure `extractorSvelte` on `extractors` option.
228
250
 
229
- You can use simple rules with `class:`, for example `class:bg-red-500={foo}` or using `shorcuts` to include multiples rules, see `src/routes/__layout.svelte` on linked example project bellow.
251
+ You can use simple rules with `class:`, for example `class:bg-red-500={foo}` or using `shorcuts` to include multiples rules, see `src/routes/__layout.svelte` on linked example project below.
230
252
 
231
253
  ```ts
232
254
  // svelte.config.js
@@ -240,7 +262,7 @@ const config = {
240
262
  // for more information about preprocessors
241
263
  preprocess: preprocess(),
242
264
  kit: {
243
- vite: {
265
+ vite: {
244
266
  plugins: [
245
267
  UnoCss({
246
268
  extractors: [extractorSvelte],
@@ -305,7 +327,7 @@ You have a `Web Components` example project on [examples/vite-lit](https://githu
305
327
 
306
328
  #### `::part` built-in support
307
329
 
308
- You can use `::part` since the plugin supports it via `shortcuts` and using `part-[<part-name>]:<rule|shortcut>` rule from `preset-mini`, for example using it with simple rules like `part-[<part-name>]:bg-green-500` or using some `shortcut`: check `src/my-element.ts` on linked example project bellow.
330
+ You can use `::part` since the plugin supports it via `shortcuts` and using `part-[<part-name>]:<rule|shortcut>` rule from `preset-mini`, for example using it with simple rules like `part-[<part-name>]:bg-green-500` or using some `shortcut`: check `src/my-element.ts` on linked example project below.
309
331
 
310
332
  The `part-[<part-name>]:<rule|shortcut>` will work only with this plugin using the `shadow-dom` mode.
311
333
 
@@ -401,4 +423,4 @@ You have a `Vite + Elm` example project on [examples/vite-elm](https://github.co
401
423
 
402
424
  ## License
403
425
 
404
- MIT License © 2021-PRESENT [Anthony Fu](https://github.com/antfu)
426
+ MIT License &copy; 2021-PRESENT [Anthony Fu](https://github.com/antfu)
package/dist/index.cjs CHANGED
@@ -40,6 +40,7 @@ function resolveId(id) {
40
40
  }
41
41
  }
42
42
  }
43
+ const RESOLVED_ID_RE = /\/__uno(_.*?)?\.css$/;
43
44
  const LAYER_PLACEHOLDER_RE = /(\\?")?#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g;
44
45
  function getLayerPlaceholder(layer) {
45
46
  return `#--unocss--{layer:${layer}}`;
@@ -119,9 +120,6 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
119
120
  };
120
121
  }
121
122
 
122
- function getHash(input, length = 8) {
123
- return crypto.createHash("sha256").update(input).digest("hex").slice(0, length);
124
- }
125
123
  function getPath(id) {
126
124
  return id.replace(/\?.*$/, "");
127
125
  }
@@ -188,6 +186,10 @@ function ChunkModeBuildPlugin({ uno, filter }) {
188
186
  };
189
187
  }
190
188
 
189
+ function getHash(input, length = 8) {
190
+ return crypto.createHash("sha256").update(input).digest("hex").slice(0, length);
191
+ }
192
+
191
193
  function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, getConfig }) {
192
194
  const vfsLayerMap = /* @__PURE__ */ new Map();
193
195
  let tasks = [];
@@ -252,12 +254,14 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
252
254
  const chunks = Object.keys(chunk.modules).filter((i) => modules.has(i));
253
255
  if (!chunks.length)
254
256
  return null;
257
+ const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
255
258
  const tokens2 = /* @__PURE__ */ new Set();
256
259
  await Promise.all(chunks.map((c) => uno.applyExtractors(modules.get(c) || "", c, tokens2)));
257
260
  let { css } = await uno.generate(tokens2, { minify: true });
258
261
  if (!css)
259
262
  return null;
260
- const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
263
+ if (!Object.keys(chunk.modules).some((i) => i.match(RESOLVED_ID_RE)))
264
+ return null;
261
265
  css = await transformCSS(css, fakeCssId);
262
266
  const hash = getHash(css);
263
267
  await cssPostPlugin.transform(getHashPlaceholder(hash), fakeCssId);
@@ -309,7 +313,6 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
309
313
  let base = "";
310
314
  const tasks = [];
311
315
  const entries = /* @__PURE__ */ new Map();
312
- const cssModules = /* @__PURE__ */ new Set();
313
316
  let invalidateTimer;
314
317
  let lastUpdate = Date.now();
315
318
  let lastServed = 0;
@@ -323,12 +326,8 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
323
326
  base = base.slice(0, base.length - 1);
324
327
  }
325
328
  function invalidate(timer = 10) {
326
- const ids = [
327
- ...entries.keys(),
328
- ...cssModules.keys()
329
- ];
330
329
  for (const server of servers) {
331
- for (const id of ids) {
330
+ for (const id of entries.keys()) {
332
331
  const mod = server.moduleGraph.getModuleById(id);
333
332
  if (!mod)
334
333
  continue;
@@ -340,14 +339,10 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
340
339
  }
341
340
  function sendUpdate() {
342
341
  lastUpdate = Date.now();
343
- const ids = [
344
- ...entries.keys(),
345
- ...cssModules.keys()
346
- ];
347
342
  for (const server of servers) {
348
343
  server.ws.send({
349
344
  type: "update",
350
- updates: Array.from(ids).map((i) => ({
345
+ updates: Array.from(entries.keys()).map((i) => ({
351
346
  acceptedPath: i,
352
347
  path: i,
353
348
  timestamp: lastUpdate,
@@ -408,8 +403,6 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
408
403
  entries.set(entry.id, entry.layer);
409
404
  return entry.id;
410
405
  }
411
- if (id.match(regexCssId))
412
- cssModules.add(id);
413
406
  },
414
407
  async load(id) {
415
408
  const layer = entries.get(getPath(id));
package/dist/index.mjs CHANGED
@@ -30,6 +30,7 @@ function resolveId(id) {
30
30
  }
31
31
  }
32
32
  }
33
+ const RESOLVED_ID_RE = /\/__uno(_.*?)?\.css$/;
33
34
  const LAYER_PLACEHOLDER_RE = /(\\?")?#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g;
34
35
  function getLayerPlaceholder(layer) {
35
36
  return `#--unocss--{layer:${layer}}`;
@@ -109,9 +110,6 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
109
110
  };
110
111
  }
111
112
 
112
- function getHash(input, length = 8) {
113
- return createHash("sha256").update(input).digest("hex").slice(0, length);
114
- }
115
113
  function getPath(id) {
116
114
  return id.replace(/\?.*$/, "");
117
115
  }
@@ -178,6 +176,10 @@ function ChunkModeBuildPlugin({ uno, filter }) {
178
176
  };
179
177
  }
180
178
 
179
+ function getHash(input, length = 8) {
180
+ return createHash("sha256").update(input).digest("hex").slice(0, length);
181
+ }
182
+
181
183
  function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, getConfig }) {
182
184
  const vfsLayerMap = /* @__PURE__ */ new Map();
183
185
  let tasks = [];
@@ -242,12 +244,14 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
242
244
  const chunks = Object.keys(chunk.modules).filter((i) => modules.has(i));
243
245
  if (!chunks.length)
244
246
  return null;
247
+ const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
245
248
  const tokens2 = /* @__PURE__ */ new Set();
246
249
  await Promise.all(chunks.map((c) => uno.applyExtractors(modules.get(c) || "", c, tokens2)));
247
250
  let { css } = await uno.generate(tokens2, { minify: true });
248
251
  if (!css)
249
252
  return null;
250
- const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
253
+ if (!Object.keys(chunk.modules).some((i) => i.match(RESOLVED_ID_RE)))
254
+ return null;
251
255
  css = await transformCSS(css, fakeCssId);
252
256
  const hash = getHash(css);
253
257
  await cssPostPlugin.transform(getHashPlaceholder(hash), fakeCssId);
@@ -299,7 +303,6 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
299
303
  let base = "";
300
304
  const tasks = [];
301
305
  const entries = /* @__PURE__ */ new Map();
302
- const cssModules = /* @__PURE__ */ new Set();
303
306
  let invalidateTimer;
304
307
  let lastUpdate = Date.now();
305
308
  let lastServed = 0;
@@ -313,12 +316,8 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
313
316
  base = base.slice(0, base.length - 1);
314
317
  }
315
318
  function invalidate(timer = 10) {
316
- const ids = [
317
- ...entries.keys(),
318
- ...cssModules.keys()
319
- ];
320
319
  for (const server of servers) {
321
- for (const id of ids) {
320
+ for (const id of entries.keys()) {
322
321
  const mod = server.moduleGraph.getModuleById(id);
323
322
  if (!mod)
324
323
  continue;
@@ -330,14 +329,10 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
330
329
  }
331
330
  function sendUpdate() {
332
331
  lastUpdate = Date.now();
333
- const ids = [
334
- ...entries.keys(),
335
- ...cssModules.keys()
336
- ];
337
332
  for (const server of servers) {
338
333
  server.ws.send({
339
334
  type: "update",
340
- updates: Array.from(ids).map((i) => ({
335
+ updates: Array.from(entries.keys()).map((i) => ({
341
336
  acceptedPath: i,
342
337
  path: i,
343
338
  timestamp: lastUpdate,
@@ -398,8 +393,6 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
398
393
  entries.set(entry.id, entry.layer);
399
394
  return entry.id;
400
395
  }
401
- if (id.match(regexCssId))
402
- cssModules.add(id);
403
396
  },
404
397
  async load(id) {
405
398
  const layer = entries.get(getPath(id));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.32.1",
3
+ "version": "0.32.9",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "keywords": [
6
6
  "unocss",
@@ -43,19 +43,18 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@rollup/pluginutils": "^4.2.1",
46
- "@unocss/config": "0.32.1",
47
- "@unocss/core": "0.32.1",
48
- "@unocss/inspector": "0.32.1",
49
- "@unocss/scope": "0.32.1",
50
- "@unocss/transformer-directives": "0.32.1",
46
+ "@unocss/config": "0.32.9",
47
+ "@unocss/core": "0.32.9",
48
+ "@unocss/inspector": "0.32.9",
49
+ "@unocss/scope": "0.32.9",
50
+ "@unocss/transformer-directives": "0.32.9",
51
51
  "magic-string": "^0.26.1"
52
52
  },
53
53
  "devDependencies": {
54
- "vite": "^2.9.5"
54
+ "vite": "^2.9.6"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "unbuild",
58
58
  "stub": "unbuild --stub"
59
- },
60
- "readme": "# @unocss/vite\n\nThe Vite plugin for UnoCSS. Ships with the `unocss` package.\n\n> This plugin does not come with any default presets. You are building a meta framework on top of UnoCSS, see [this file](https://github.com/unocss/unocss/blob/main/packages/unocss/src/vite.ts) for an example to bind the default presets.\n\n## Installation\n\n```bash\nnpm i -D unocss\n```\n\n```ts\n// vite.config.ts\nimport Unocss from 'unocss/vite'\n\nexport default {\n plugins: [\n Unocss({ /* options */ }),\n ],\n}\n```\n\nAdd `uno.css` to your main entry:\n\n```ts\n// main.ts\nimport 'uno.css'\n```\n\n## Modes\n\nThe Vite plugin comes with a set of modes that enable different behaviors.\n\n### global (default)\n\nThis is the default mode for the plugin: in this mode you need to add the import of `uno.css` on your entry point.\n\nThis mode enables a set of Vite plugins for `build` and for `dev` with `HMR` support.\n\nThe generated `css` will be a global stylesheet injected on the `index.html`.\n\n### vue-scoped\n\nThis mode will inject generated CSS to Vue SFC's `<style scoped>` for isolation.\n\n### svelte-scoped\n\nThis mode will inject generated CSS to Svelte's `<style>` for isolation.\n\n### shadow-dom\n\nSince `Web Components` uses `Shadow DOM`, there is no way to style content directly from a global stylesheet (unless you use `custom css vars`, those will penetrate the `Shadow DOM`), you need to inline the generated css by the plugin into the `Shadow DOM` style.\n\nTo inline the generated css, you only need to configure the plugin mode to `shadow-dom` and include `@unocss-placeholder` magic placeholder on each web component style css block.\n\n### per-module (Experimental)\n\nThis mode will generate a CSS sheet for each module, can be scoped.\n\n### dist-chunk (Experimental)\n\nThis mode will generate a CSS sheet for each code chunk on build, great for MPA.\n\n## \"Design in DevTools\"\n\nBecause of limitation of \"on-demand\" where the DevTools don't know those you haven't used in your source code yet. So if you want to try how things work by directly changing the classes in DevTools, just add the following lines to your main entry.\n\n```ts\nimport 'uno.css'\nimport 'virtual:unocss-devtools'\n```\n\n> ⚠️ Please use it with caution, under the hood we use [`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) to detect the class changes. Which means not only your manual changes but also the changes made by your scripts will be detected and included in the stylesheet. This could cause some misalignment between dev and the production build when you add dynamic classes based on some logic in script tags. We recommended adding your dynamic parts to the [safelist](https://github.com/unocss/unocss/issues/511) or setup UI regression tests for your production build if possible.\n\n`virtual:unocss-devtools` will be an empty bundle in production.\n\n## Frameworks\n\nSome UI/App frameworks have some caveats that must be fixed to make it work, if you're using one of the following frameworks, just apply the suggestions.\n\n### React\n\n**WARNING**: You should import the `uno.css` virtual module using `import 'virtual:uno.css'` instead `import 'uno.css'`. When you start the dev server first time, you'll need to update some style module to get it working (we're trying to fix it).\n\nIf you're using `@vitejs/plugin-react`:\n\n```ts\n// vite.config.js\nimport react from '@vitejs/plugin-react'\nimport Unocss from 'unocss/vite'\n\nexport default {\n plugins: [\n react(),\n Unocss({\n /* options */\n }),\n ],\n}\n```\n\nor if you're using `@vitejs/plugin-react-refresh`:\n\n```ts\n// vite.config.js\nimport reactRefresh from '@vitejs/plugin-react-refresh'\nimport Unocss from 'unocss/vite'\n\nexport default {\n plugins: [\n reactRefresh(),\n Unocss({\n /* options */\n }),\n ],\n}\n```\n\nIf you're using `@unocss/preset-attributify` you should remove `tsc` from the `build` script.\n\nIf you are using `@vitejs/plugin-react` with `@unocss/preset-attributify`, you must add the plugin before `@vitejs/plugin-react`.\n\n```ts\n// vite.config.js\nimport react from '@vitejs/plugin-react'\nimport Unocss from 'unocss/vite'\n\nexport default {\n plugins: [\n Unocss({\n /* options */\n }),\n react(),\n ],\n}\n```\n\nYou have a `React` example project on [examples/vite-react](https://github.com/unocss/unocss/tree/main/examples/vite-react) directory using both plugins, check the scripts on `package.json` and its Vite configuration file.\n\n### Preact\n\nIf you're using `@preact/preset-vite`:\n\n```ts\n// vite.config.js\nimport preact from '@preact/preset-vite'\nimport Unocss from 'unocss/vite'\n\nexport default {\n plugins: [\n preact(),\n Unocss({\n /* options */\n }),\n ],\n}\n```\n\nor if you're using `@prefresh/vite`:\n\n```ts\n// vite.config.js\nimport prefresh from '@prefresh/vite'\nimport Unocss from 'unocss/vite'\n\nexport default {\n plugins: [\n prefresh(),\n Unocss({\n /* options */\n }),\n ],\n}\n```\n\nIf you're using `@unocss/preset-attributify` you should remove `tsc` from the `build` script.\n\nIf you are using `@preact/preset-vite` with `@unocss/preset-attributify`, you must add the plugin before `@preact/preset-vite`.\n\n```ts\n// vite.config.js\nimport preact from '@preact/preset-vite'\nimport Unocss from 'unocss/vite'\n\nexport default {\n plugins: [\n Unocss({\n /* options */\n }),\n preact(),\n ],\n}\n```\n\nYou have a `Preact` example project on [examples/vite-preact](https://github.com/unocss/unocss/tree/main/examples/vite-preact) directory using both plugins, check the scripts on `package.json` and its Vite configuration file.\n\n### Svelte\n\nYou must add the plugin before `@sveltejs/vite-plugin-svelte`.\n\nTo support `class:foo` and `class:foo={bar}` add the plugin and configure `extractorSvelte` on `extractors` option.\n\nYou can use simple rules with `class:`, for example `class:bg-red-500={foo}` or using `shorcuts` to include multiples rules, see `src/App.svelte` on linked example project bellow.\n\n```ts\n// vite.config.js\nimport { svelte } from '@sveltejs/vite-plugin-svelte'\nimport Unocss from 'unocss/vite'\nimport { extractorSvelte } from '@unocss/core'\n\nexport default {\n plugins: [\n Unocss({\n extractors: [extractorSvelte],\n /* more options */\n }),\n svelte(),\n ],\n}\n```\n\nYou have a `Vite + Svelte` example project on [examples/vite-svelte](https://github.com/unocss/unocss/tree/main/examples/vite-svelte) directory.\n\n### Sveltekit\n\nTo support `class:foo` and `class:foo={bar}` add the plugin and configure `extractorSvelte` on `extractors` option.\n\nYou can use simple rules with `class:`, for example `class:bg-red-500={foo}` or using `shorcuts` to include multiples rules, see `src/routes/__layout.svelte` on linked example project bellow.\n\n```ts\n// svelte.config.js\nimport preprocess from 'svelte-preprocess'\nimport UnoCss from 'unocss/vite'\nimport { extractorSvelte } from '@unocss/core'\n\n/** @type {import('@sveltejs/kit').Config} */\nconst config = {\n // Consult https://github.com/sveltejs/svelte-preprocess\n // for more information about preprocessors\n preprocess: preprocess(),\n kit: {\n vite: {\n plugins: [\n UnoCss({\n extractors: [extractorSvelte],\n /* more options */\n }),\n ],\n },\n },\n}\n```\n\nYou have a `SvelteKit` example project on [examples/sveltekit](https://github.com/unocss/unocss/tree/main/examples/sveltekit) directory.\n\n### Web Components\n\nTo work with web components you need to enable `shadow-dom` mode on the plugin.\n\nDon't forget to remove the import for `uno.css` since the `shadow-dom` mode will not expose it and the application will not work.\n\n```ts\n// vite.config.js\nimport Unocss from 'unocss/vite'\n\nexport default {\n plugins: [\n Unocss({\n mode: 'shadow-dom',\n /* more options */\n }),\n ],\n}\n```\n\nOn each `web component` just add `@unocss-placeholder` to its style css block:\n```ts\nconst template = document.createElement('template')\ntemplate.innerHTML = `\n<style>\n:host {...}\n@unocss-placeholder\n</style>\n<div class=\"m-1em\">\n...\n</div>\n`\n```\n\nIf you're using [Lit](https://lit.dev/):\n\n```ts\n@customElement('my-element')\nexport class MyElement extends LitElement {\n static styles = css`\n :host {...}\n @unocss-placeholder\n `\n // ...\n}\n```\n\nYou have a `Web Components` example project on [examples/vite-lit](https://github.com/unocss/unocss/tree/main/examples/vite-lit) directory.\n\n#### `::part` built-in support\n\nYou can use `::part` since the plugin supports it via `shortcuts` and using `part-[<part-name>]:<rule|shortcut>` rule from `preset-mini`, for example using it with simple rules like `part-[<part-name>]:bg-green-500` or using some `shortcut`: check `src/my-element.ts` on linked example project bellow.\n\nThe `part-[<part-name>]:<rule|shortcut>` will work only with this plugin using the `shadow-dom` mode.\n\nThe plugin uses `nth-of-type` to avoid collisions with multiple parts in the same web component and for the same parts on distinct web components, you don't need to worry about it, the plugin will take care for you.\n\n```ts\n// vite.config.js\nimport Unocss from 'unocss/vite'\n\nexport default {\n plugins: [\n Unocss({\n mode: 'shadow-dom',\n shortcuts: [\n { 'cool-blue': 'bg-blue-500 text-white' },\n { 'cool-green': 'bg-green-500 text-black' },\n ],\n /* more options */\n }),\n ],\n}\n```\n\nthen in your web components:\n\n```ts\n// my-container-wc.ts\nconst template = document.createElement('template')\ntemplate.innerHTML = `\n<style>\n@unocss-placeholder\n</style>\n<my-wc-with-parts class=\"part-[cool-part]:cool-blue part-[another-cool-part]:cool-green\">...</my-wc-with-parts>\n`\n```\n\n```ts\n// my-wc-with-parts.ts\nconst template = document.createElement('template')\ntemplate.innerHTML = `\n<style>\n@unocss-placeholder\n</style>\n<div>\n <div part=\"cool-part\">...</div>\n <div part=\"another-cool-part\">...</div>\n</div>\n`\n```\n\n### Solid\n\n**WARNING**: You should import the `uno.css` virtual module using `import 'virtual:uno.css'` instead `import 'uno.css'`. When you start the dev server first time, you'll need to update some style module to get it working (we're trying to fix it).\n\n```ts\n// vite.config.js\nimport solidPlugin from 'vite-plugin-solid'\nimport Unocss from 'unocss/vite'\n\nexport default {\n plugins: [\n solidPlugin(),\n Unocss({\n /* options */\n }),\n ],\n}\n```\n\nYou have a `Vite + Solid` example project on [examples/vite-solid](https://github.com/unocss/unocss/tree/main/examples/vite-solid) directory.\n\n### Elm\n\nYou need to add the `vite-plugin-elm` plugin before UnoCSS's plugin.\n\n```ts\n// vite.config.js\nimport { defineConfig } from 'vite'\nimport elmPlugin from 'vite-plugin-elm'\nimport Unocss from 'unocss/vite'\n\nexport default defineConfig({\n plugins: [\n elmPlugin(),\n Unocss({\n /* options */\n }),\n ],\n})\n```\n\nYou have a `Vite + Elm` example project on [examples/vite-elm](https://github.com/unocss/unocss/tree/main/examples/vite-elm) directory.\n\n## License\n\nMIT License © 2021-PRESENT [Anthony Fu](https://github.com/antfu)\n"
59
+ }
61
60
  }