@unocss/vite 0.32.7 → 0.32.11

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
@@ -423,4 +423,4 @@ You have a `Vite + Elm` example project on [examples/vite-elm](https://github.co
423
423
 
424
424
  ## License
425
425
 
426
- 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
@@ -3,14 +3,14 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const UnocssInspector = require('@unocss/inspector');
6
- const pluginutils = require('@rollup/pluginutils');
7
- const config = require('@unocss/config');
8
- const core = require('@unocss/core');
9
6
  const crypto = require('crypto');
7
+ const core = require('@unocss/core');
8
+ const pluginutils = require('@rollup/pluginutils');
10
9
  const MagicString = require('magic-string');
11
10
  const fs = require('fs');
12
11
  const path = require('path');
13
12
  const url = require('url');
13
+ const config = require('@unocss/config');
14
14
 
15
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
16
16
 
@@ -18,8 +18,7 @@ const UnocssInspector__default = /*#__PURE__*/_interopDefaultLegacy(UnocssInspec
18
18
  const MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
19
19
  const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
20
20
 
21
- const regexCssId = /\.(css|postcss|sass|scss|less|stylus|styl)$/;
22
- const defaultExclude = [regexCssId];
21
+ const defaultExclude = [core.cssIdRE];
23
22
  const defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/, /\.elm$/];
24
23
 
25
24
  const VIRTUAL_ENTRY_ALIAS = [
@@ -40,6 +39,7 @@ function resolveId(id) {
40
39
  }
41
40
  }
42
41
  }
42
+ const RESOLVED_ID_RE = /\/__uno(_.*?)?\.css$/;
43
43
  const LAYER_PLACEHOLDER_RE = /(\\?")?#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g;
44
44
  function getLayerPlaceholder(layer) {
45
45
  return `#--unocss--{layer:${layer}}`;
@@ -50,6 +50,7 @@ function getHashPlaceholder(hash) {
50
50
  }
51
51
 
52
52
  const INCLUDE_COMMENT = "@unocss-include";
53
+ const IGNORE_COMMENT = "@unocss-ignore";
53
54
  const CSS_PLACEHOLDER = "@unocss-placeholder";
54
55
 
55
56
  function createContext(configOrPath, defaults = {}, extraConfigSources = [], resolveConfigResult = () => {
@@ -93,6 +94,8 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
93
94
  invalidate();
94
95
  }
95
96
  const filter = (code, id) => {
97
+ if (code.includes(IGNORE_COMMENT))
98
+ return false;
96
99
  return code.includes(INCLUDE_COMMENT) || code.includes(CSS_PLACEHOLDER) || rollupFilter(id);
97
100
  };
98
101
  async function getConfig() {
@@ -122,6 +125,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
122
125
  function getPath(id) {
123
126
  return id.replace(/\?.*$/, "");
124
127
  }
128
+
129
+ function getHash(input, length = 8) {
130
+ return crypto.createHash("sha256").update(input).digest("hex").slice(0, length);
131
+ }
132
+
125
133
  function replaceAsync(string, searchValue, replacer) {
126
134
  try {
127
135
  if (typeof replacer === "function") {
@@ -185,10 +193,6 @@ function ChunkModeBuildPlugin({ uno, filter }) {
185
193
  };
186
194
  }
187
195
 
188
- function getHash(input, length = 8) {
189
- return crypto.createHash("sha256").update(input).digest("hex").slice(0, length);
190
- }
191
-
192
196
  function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, getConfig }) {
193
197
  const vfsLayerMap = /* @__PURE__ */ new Map();
194
198
  let tasks = [];
@@ -253,12 +257,14 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
253
257
  const chunks = Object.keys(chunk.modules).filter((i) => modules.has(i));
254
258
  if (!chunks.length)
255
259
  return null;
260
+ const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
256
261
  const tokens2 = /* @__PURE__ */ new Set();
257
262
  await Promise.all(chunks.map((c) => uno.applyExtractors(modules.get(c) || "", c, tokens2)));
258
263
  let { css } = await uno.generate(tokens2, { minify: true });
259
264
  if (!css)
260
265
  return null;
261
- const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
266
+ if (!Object.keys(chunk.modules).some((i) => i.match(RESOLVED_ID_RE)))
267
+ return null;
262
268
  css = await transformCSS(css, fakeCssId);
263
269
  const hash = getHash(css);
264
270
  await cssPostPlugin.transform(getHashPlaceholder(hash), fakeCssId);
@@ -310,7 +316,6 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
310
316
  let base = "";
311
317
  const tasks = [];
312
318
  const entries = /* @__PURE__ */ new Map();
313
- const cssModules = /* @__PURE__ */ new Set();
314
319
  let invalidateTimer;
315
320
  let lastUpdate = Date.now();
316
321
  let lastServed = 0;
@@ -324,12 +329,8 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
324
329
  base = base.slice(0, base.length - 1);
325
330
  }
326
331
  function invalidate(timer = 10) {
327
- const ids = [
328
- ...entries.keys(),
329
- ...cssModules.keys()
330
- ];
331
332
  for (const server of servers) {
332
- for (const id of ids) {
333
+ for (const id of entries.keys()) {
333
334
  const mod = server.moduleGraph.getModuleById(id);
334
335
  if (!mod)
335
336
  continue;
@@ -341,14 +342,10 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
341
342
  }
342
343
  function sendUpdate() {
343
344
  lastUpdate = Date.now();
344
- const ids = [
345
- ...entries.keys(),
346
- ...cssModules.keys()
347
- ];
348
345
  for (const server of servers) {
349
346
  server.ws.send({
350
347
  type: "update",
351
- updates: Array.from(ids).map((i) => ({
348
+ updates: Array.from(entries.keys()).map((i) => ({
352
349
  acceptedPath: i,
353
350
  path: i,
354
351
  timestamp: lastUpdate,
@@ -409,8 +406,6 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
409
406
  entries.set(entry.id, entry.layer);
410
407
  return entry.id;
411
408
  }
412
- if (id.match(regexCssId))
413
- cssModules.add(id);
414
409
  },
415
410
  async load(id) {
416
411
  const layer = entries.get(getPath(id));
@@ -697,6 +692,8 @@ function ConfigHMRPlugin(ctx) {
697
692
 
698
693
  function initTransformerPlugins(ctx) {
699
694
  async function applyTransformers(code, id, enforce) {
695
+ if (code.includes(IGNORE_COMMENT))
696
+ return;
700
697
  const transformers = (ctx.uno.config.transformers || []).filter((i) => i.enforce === enforce);
701
698
  if (!transformers.length)
702
699
  return;
package/dist/index.mjs CHANGED
@@ -1,15 +1,14 @@
1
1
  import UnocssInspector from '@unocss/inspector';
2
- import { createFilter } from '@rollup/pluginutils';
3
- import { loadConfig } from '@unocss/config';
4
- import { createGenerator, BetterMap, toEscapedSelector } from '@unocss/core';
5
2
  import { createHash } from 'crypto';
3
+ import { cssIdRE, createGenerator, BetterMap, toEscapedSelector } from '@unocss/core';
4
+ import { createFilter } from '@rollup/pluginutils';
6
5
  import MagicString from 'magic-string';
7
6
  import fs from 'fs';
8
7
  import { resolve, dirname } from 'path';
9
8
  import { fileURLToPath } from 'url';
9
+ import { loadConfig } from '@unocss/config';
10
10
 
11
- const regexCssId = /\.(css|postcss|sass|scss|less|stylus|styl)$/;
12
- const defaultExclude = [regexCssId];
11
+ const defaultExclude = [cssIdRE];
13
12
  const defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/, /\.elm$/];
14
13
 
15
14
  const VIRTUAL_ENTRY_ALIAS = [
@@ -30,6 +29,7 @@ function resolveId(id) {
30
29
  }
31
30
  }
32
31
  }
32
+ const RESOLVED_ID_RE = /\/__uno(_.*?)?\.css$/;
33
33
  const LAYER_PLACEHOLDER_RE = /(\\?")?#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g;
34
34
  function getLayerPlaceholder(layer) {
35
35
  return `#--unocss--{layer:${layer}}`;
@@ -40,6 +40,7 @@ function getHashPlaceholder(hash) {
40
40
  }
41
41
 
42
42
  const INCLUDE_COMMENT = "@unocss-include";
43
+ const IGNORE_COMMENT = "@unocss-ignore";
43
44
  const CSS_PLACEHOLDER = "@unocss-placeholder";
44
45
 
45
46
  function createContext(configOrPath, defaults = {}, extraConfigSources = [], resolveConfigResult = () => {
@@ -83,6 +84,8 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
83
84
  invalidate();
84
85
  }
85
86
  const filter = (code, id) => {
87
+ if (code.includes(IGNORE_COMMENT))
88
+ return false;
86
89
  return code.includes(INCLUDE_COMMENT) || code.includes(CSS_PLACEHOLDER) || rollupFilter(id);
87
90
  };
88
91
  async function getConfig() {
@@ -112,6 +115,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
112
115
  function getPath(id) {
113
116
  return id.replace(/\?.*$/, "");
114
117
  }
118
+
119
+ function getHash(input, length = 8) {
120
+ return createHash("sha256").update(input).digest("hex").slice(0, length);
121
+ }
122
+
115
123
  function replaceAsync(string, searchValue, replacer) {
116
124
  try {
117
125
  if (typeof replacer === "function") {
@@ -175,10 +183,6 @@ function ChunkModeBuildPlugin({ uno, filter }) {
175
183
  };
176
184
  }
177
185
 
178
- function getHash(input, length = 8) {
179
- return createHash("sha256").update(input).digest("hex").slice(0, length);
180
- }
181
-
182
186
  function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, getConfig }) {
183
187
  const vfsLayerMap = /* @__PURE__ */ new Map();
184
188
  let tasks = [];
@@ -243,12 +247,14 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
243
247
  const chunks = Object.keys(chunk.modules).filter((i) => modules.has(i));
244
248
  if (!chunks.length)
245
249
  return null;
250
+ const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
246
251
  const tokens2 = /* @__PURE__ */ new Set();
247
252
  await Promise.all(chunks.map((c) => uno.applyExtractors(modules.get(c) || "", c, tokens2)));
248
253
  let { css } = await uno.generate(tokens2, { minify: true });
249
254
  if (!css)
250
255
  return null;
251
- const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
256
+ if (!Object.keys(chunk.modules).some((i) => i.match(RESOLVED_ID_RE)))
257
+ return null;
252
258
  css = await transformCSS(css, fakeCssId);
253
259
  const hash = getHash(css);
254
260
  await cssPostPlugin.transform(getHashPlaceholder(hash), fakeCssId);
@@ -300,7 +306,6 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
300
306
  let base = "";
301
307
  const tasks = [];
302
308
  const entries = /* @__PURE__ */ new Map();
303
- const cssModules = /* @__PURE__ */ new Set();
304
309
  let invalidateTimer;
305
310
  let lastUpdate = Date.now();
306
311
  let lastServed = 0;
@@ -314,12 +319,8 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
314
319
  base = base.slice(0, base.length - 1);
315
320
  }
316
321
  function invalidate(timer = 10) {
317
- const ids = [
318
- ...entries.keys(),
319
- ...cssModules.keys()
320
- ];
321
322
  for (const server of servers) {
322
- for (const id of ids) {
323
+ for (const id of entries.keys()) {
323
324
  const mod = server.moduleGraph.getModuleById(id);
324
325
  if (!mod)
325
326
  continue;
@@ -331,14 +332,10 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
331
332
  }
332
333
  function sendUpdate() {
333
334
  lastUpdate = Date.now();
334
- const ids = [
335
- ...entries.keys(),
336
- ...cssModules.keys()
337
- ];
338
335
  for (const server of servers) {
339
336
  server.ws.send({
340
337
  type: "update",
341
- updates: Array.from(ids).map((i) => ({
338
+ updates: Array.from(entries.keys()).map((i) => ({
342
339
  acceptedPath: i,
343
340
  path: i,
344
341
  timestamp: lastUpdate,
@@ -399,8 +396,6 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
399
396
  entries.set(entry.id, entry.layer);
400
397
  return entry.id;
401
398
  }
402
- if (id.match(regexCssId))
403
- cssModules.add(id);
404
399
  },
405
400
  async load(id) {
406
401
  const layer = entries.get(getPath(id));
@@ -687,6 +682,8 @@ function ConfigHMRPlugin(ctx) {
687
682
 
688
683
  function initTransformerPlugins(ctx) {
689
684
  async function applyTransformers(code, id, enforce) {
685
+ if (code.includes(IGNORE_COMMENT))
686
+ return;
690
687
  const transformers = (ctx.uno.config.transformers || []).filter((i) => i.enforce === enforce);
691
688
  if (!transformers.length)
692
689
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.32.7",
3
+ "version": "0.32.11",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "keywords": [
6
6
  "unocss",
@@ -43,19 +43,19 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@rollup/pluginutils": "^4.2.1",
46
- "@unocss/config": "0.32.7",
47
- "@unocss/core": "0.32.7",
48
- "@unocss/inspector": "0.32.7",
49
- "@unocss/scope": "0.32.7",
50
- "@unocss/transformer-directives": "0.32.7",
46
+ "@unocss/config": "0.32.11",
47
+ "@unocss/core": "0.32.11",
48
+ "@unocss/inspector": "0.32.11",
49
+ "@unocss/scope": "0.32.11",
50
+ "@unocss/transformer-directives": "0.32.11",
51
51
  "magic-string": "^0.26.1"
52
52
  },
53
53
  "devDependencies": {
54
+ "@unocss/shared-integration": "0.32.11",
54
55
  "vite": "^2.9.6"
55
56
  },
56
57
  "scripts": {
57
58
  "build": "unbuild",
58
59
  "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### Presetless usage\n\n```bash\nnpm i -D @unocss/vite\n```\n\n```ts\n// vite.config.ts\nimport Unocss from '@unocss/vite'\n\nexport default {\n plugins: [\n Unocss({\n presets: [\n /* no presets by default */\n ],\n /* options */\n }),\n ],\n}\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 below.\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 below.\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 below.\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"
60
+ }
61
61
  }