@unocss/vite 0.44.0 → 0.44.1
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/README.md +10 -16
- package/dist/index.cjs +59 -36
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +59 -36
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -251,26 +251,20 @@ To support `class:foo` and `class:foo={bar}` add the plugin and configure `extra
|
|
|
251
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.
|
|
252
252
|
|
|
253
253
|
```ts
|
|
254
|
-
//
|
|
255
|
-
import
|
|
254
|
+
// vite.config.js
|
|
255
|
+
import { sveltekit } from '@sveltejs/kit/vite'
|
|
256
256
|
import UnoCss from 'unocss/vite'
|
|
257
257
|
import { extractorSvelte } from '@unocss/core'
|
|
258
258
|
|
|
259
|
-
/** @type {import('
|
|
259
|
+
/** @type {import('vite').UserConfig} */
|
|
260
260
|
const config = {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
extractors: [extractorSvelte],
|
|
269
|
-
/* more options */
|
|
270
|
-
}),
|
|
271
|
-
],
|
|
272
|
-
},
|
|
273
|
-
},
|
|
261
|
+
plugins: [
|
|
262
|
+
sveltekit(),
|
|
263
|
+
UnoCss({
|
|
264
|
+
extractors: [extractorSvelte],
|
|
265
|
+
/* more options */
|
|
266
|
+
}),
|
|
267
|
+
],
|
|
274
268
|
}
|
|
275
269
|
```
|
|
276
270
|
|
package/dist/index.cjs
CHANGED
|
@@ -354,7 +354,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
354
354
|
chunk.code = await replaceAsync(js, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
355
355
|
replaced = true;
|
|
356
356
|
const css = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || "";
|
|
357
|
-
return css;
|
|
357
|
+
return css.replace(/\n/g, "").replace(/(?<!\\)(['"])/g, "\\$1");
|
|
358
358
|
});
|
|
359
359
|
}
|
|
360
360
|
}
|
|
@@ -528,44 +528,67 @@ function PerModuleModePlugin({ uno, filter }) {
|
|
|
528
528
|
}]
|
|
529
529
|
});
|
|
530
530
|
};
|
|
531
|
-
return
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
};
|
|
553
|
-
},
|
|
554
|
-
resolveId(id) {
|
|
555
|
-
return id.startsWith(VIRTUAL_PREFIX) ? id : null;
|
|
531
|
+
return [
|
|
532
|
+
{
|
|
533
|
+
name: "unocss:module-scope:pre",
|
|
534
|
+
enforce: "pre",
|
|
535
|
+
async transform(code, id) {
|
|
536
|
+
if (!filter(code, id))
|
|
537
|
+
return;
|
|
538
|
+
const hash = getHash(id);
|
|
539
|
+
const { css } = await uno.generate(code, {
|
|
540
|
+
id,
|
|
541
|
+
preflights: true
|
|
542
|
+
});
|
|
543
|
+
if (!css)
|
|
544
|
+
return null;
|
|
545
|
+
moduleMap.set(hash, [id, css]);
|
|
546
|
+
invalidate(hash);
|
|
547
|
+
return {
|
|
548
|
+
code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
|
|
549
|
+
map: null
|
|
550
|
+
};
|
|
551
|
+
}
|
|
556
552
|
},
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
553
|
+
{
|
|
554
|
+
name: "unocss:module-scope",
|
|
555
|
+
enforce: "post",
|
|
556
|
+
configureServer(_server) {
|
|
557
|
+
server = _server;
|
|
558
|
+
},
|
|
559
|
+
async transform(code, id) {
|
|
560
|
+
if (!filter(code, id))
|
|
561
|
+
return;
|
|
562
|
+
const hash = getHash(id);
|
|
563
|
+
const hasScope = code.match(SCOPE_IMPORT_RE);
|
|
564
|
+
const { css } = await uno.generate(code, { id, scope: hasScope ? `.${hash}` : void 0, preflights: false });
|
|
565
|
+
if (!css && !hasScope)
|
|
566
|
+
return null;
|
|
567
|
+
if (hasScope)
|
|
568
|
+
code = code.replace(SCOPE_IMPORT_RE, ` from 'data:text/javascript;base64,${Buffer.from(`export default () => "${hash}"`).toString("base64")}'`);
|
|
569
|
+
moduleMap.set(hash, [id, css]);
|
|
570
|
+
invalidate(hash);
|
|
571
|
+
return {
|
|
572
|
+
code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
|
|
573
|
+
map: null
|
|
574
|
+
};
|
|
575
|
+
},
|
|
576
|
+
resolveId(id) {
|
|
577
|
+
return id.startsWith(VIRTUAL_PREFIX) ? id : null;
|
|
578
|
+
},
|
|
579
|
+
load(id) {
|
|
580
|
+
if (!id.startsWith(VIRTUAL_PREFIX))
|
|
581
|
+
return null;
|
|
582
|
+
const hash = id.slice(VIRTUAL_PREFIX.length, -".css".length);
|
|
583
|
+
const [source, css] = moduleMap.get(hash) || [];
|
|
584
|
+
if (source)
|
|
585
|
+
this.addWatchFile(source);
|
|
586
|
+
return `
|
|
565
587
|
/* unocss ${source} */
|
|
566
588
|
${css}`;
|
|
589
|
+
}
|
|
567
590
|
}
|
|
568
|
-
|
|
591
|
+
];
|
|
569
592
|
}
|
|
570
593
|
|
|
571
594
|
function VueScopedPlugin({ uno, ready }) {
|
|
@@ -956,7 +979,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
|
|
|
956
979
|
if (inlineConfig.inspector !== false)
|
|
957
980
|
plugins.push(UnocssInspector__default(ctx));
|
|
958
981
|
if (mode === "per-module") {
|
|
959
|
-
plugins.push(PerModuleModePlugin(ctx));
|
|
982
|
+
plugins.push(...PerModuleModePlugin(ctx));
|
|
960
983
|
} else if (mode === "vue-scoped") {
|
|
961
984
|
plugins.push(VueScopedPlugin(ctx));
|
|
962
985
|
} else if (mode === "svelte-scoped") {
|
package/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ declare function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, ge
|
|
|
45
45
|
|
|
46
46
|
declare function GlobalModePlugin(ctx: UnocssPluginContext): vite.Plugin[];
|
|
47
47
|
|
|
48
|
-
declare function PerModuleModePlugin({ uno, filter }: UnocssPluginContext): Plugin;
|
|
48
|
+
declare function PerModuleModePlugin({ uno, filter }: UnocssPluginContext): Plugin[];
|
|
49
49
|
|
|
50
50
|
declare function VueScopedPlugin({ uno, ready }: UnocssPluginContext): Plugin;
|
|
51
51
|
|
package/dist/index.mjs
CHANGED
|
@@ -344,7 +344,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
344
344
|
chunk.code = await replaceAsync(js, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
345
345
|
replaced = true;
|
|
346
346
|
const css = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || "";
|
|
347
|
-
return css;
|
|
347
|
+
return css.replace(/\n/g, "").replace(/(?<!\\)(['"])/g, "\\$1");
|
|
348
348
|
});
|
|
349
349
|
}
|
|
350
350
|
}
|
|
@@ -518,44 +518,67 @@ function PerModuleModePlugin({ uno, filter }) {
|
|
|
518
518
|
}]
|
|
519
519
|
});
|
|
520
520
|
};
|
|
521
|
-
return
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
};
|
|
543
|
-
},
|
|
544
|
-
resolveId(id) {
|
|
545
|
-
return id.startsWith(VIRTUAL_PREFIX) ? id : null;
|
|
521
|
+
return [
|
|
522
|
+
{
|
|
523
|
+
name: "unocss:module-scope:pre",
|
|
524
|
+
enforce: "pre",
|
|
525
|
+
async transform(code, id) {
|
|
526
|
+
if (!filter(code, id))
|
|
527
|
+
return;
|
|
528
|
+
const hash = getHash(id);
|
|
529
|
+
const { css } = await uno.generate(code, {
|
|
530
|
+
id,
|
|
531
|
+
preflights: true
|
|
532
|
+
});
|
|
533
|
+
if (!css)
|
|
534
|
+
return null;
|
|
535
|
+
moduleMap.set(hash, [id, css]);
|
|
536
|
+
invalidate(hash);
|
|
537
|
+
return {
|
|
538
|
+
code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
|
|
539
|
+
map: null
|
|
540
|
+
};
|
|
541
|
+
}
|
|
546
542
|
},
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
543
|
+
{
|
|
544
|
+
name: "unocss:module-scope",
|
|
545
|
+
enforce: "post",
|
|
546
|
+
configureServer(_server) {
|
|
547
|
+
server = _server;
|
|
548
|
+
},
|
|
549
|
+
async transform(code, id) {
|
|
550
|
+
if (!filter(code, id))
|
|
551
|
+
return;
|
|
552
|
+
const hash = getHash(id);
|
|
553
|
+
const hasScope = code.match(SCOPE_IMPORT_RE);
|
|
554
|
+
const { css } = await uno.generate(code, { id, scope: hasScope ? `.${hash}` : void 0, preflights: false });
|
|
555
|
+
if (!css && !hasScope)
|
|
556
|
+
return null;
|
|
557
|
+
if (hasScope)
|
|
558
|
+
code = code.replace(SCOPE_IMPORT_RE, ` from 'data:text/javascript;base64,${Buffer.from(`export default () => "${hash}"`).toString("base64")}'`);
|
|
559
|
+
moduleMap.set(hash, [id, css]);
|
|
560
|
+
invalidate(hash);
|
|
561
|
+
return {
|
|
562
|
+
code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
|
|
563
|
+
map: null
|
|
564
|
+
};
|
|
565
|
+
},
|
|
566
|
+
resolveId(id) {
|
|
567
|
+
return id.startsWith(VIRTUAL_PREFIX) ? id : null;
|
|
568
|
+
},
|
|
569
|
+
load(id) {
|
|
570
|
+
if (!id.startsWith(VIRTUAL_PREFIX))
|
|
571
|
+
return null;
|
|
572
|
+
const hash = id.slice(VIRTUAL_PREFIX.length, -".css".length);
|
|
573
|
+
const [source, css] = moduleMap.get(hash) || [];
|
|
574
|
+
if (source)
|
|
575
|
+
this.addWatchFile(source);
|
|
576
|
+
return `
|
|
555
577
|
/* unocss ${source} */
|
|
556
578
|
${css}`;
|
|
579
|
+
}
|
|
557
580
|
}
|
|
558
|
-
|
|
581
|
+
];
|
|
559
582
|
}
|
|
560
583
|
|
|
561
584
|
function VueScopedPlugin({ uno, ready }) {
|
|
@@ -946,7 +969,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
|
|
|
946
969
|
if (inlineConfig.inspector !== false)
|
|
947
970
|
plugins.push(UnocssInspector(ctx));
|
|
948
971
|
if (mode === "per-module") {
|
|
949
|
-
plugins.push(PerModuleModePlugin(ctx));
|
|
972
|
+
plugins.push(...PerModuleModePlugin(ctx));
|
|
950
973
|
} else if (mode === "vue-scoped") {
|
|
951
974
|
plugins.push(VueScopedPlugin(ctx));
|
|
952
975
|
} else if (mode === "svelte-scoped") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.44.
|
|
3
|
+
"version": "0.44.1",
|
|
4
4
|
"description": "The Vite plugin for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,15 +43,15 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@rollup/pluginutils": "^4.2.1",
|
|
46
|
-
"@unocss/config": "0.44.
|
|
47
|
-
"@unocss/core": "0.44.
|
|
48
|
-
"@unocss/inspector": "0.44.
|
|
49
|
-
"@unocss/scope": "0.44.
|
|
50
|
-
"@unocss/transformer-directives": "0.44.
|
|
46
|
+
"@unocss/config": "0.44.1",
|
|
47
|
+
"@unocss/core": "0.44.1",
|
|
48
|
+
"@unocss/inspector": "0.44.1",
|
|
49
|
+
"@unocss/scope": "0.44.1",
|
|
50
|
+
"@unocss/transformer-directives": "0.44.1",
|
|
51
51
|
"magic-string": "^0.26.2"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@unocss/shared-integration": "0.44.
|
|
54
|
+
"@unocss/shared-integration": "0.44.1",
|
|
55
55
|
"vite": "^2.9.12"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|