@vanilla-extract/vite-plugin 2.0.0 → 2.1.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/CHANGELOG.md +32 -0
- package/README.md +250 -82
- package/dist/declarations/src/index.d.ts +6 -1
- package/dist/vanilla-extract-vite-plugin.cjs.dev.js +10 -11
- package/dist/vanilla-extract-vite-plugin.cjs.prod.js +10 -11
- package/dist/vanilla-extract-vite-plugin.esm.js +11 -12
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @vanilla-extract/vite-plugin
|
|
2
2
|
|
|
3
|
+
## 2.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#393](https://github.com/seek-oss/vanilla-extract/pull/393) [`2f379f1`](https://github.com/seek-oss/vanilla-extract/commit/2f379f118c2a2fe6dc08a1cc15a395dbc0f17ece) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Fix compilation errors in Vite 2.6
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`2f379f1`](https://github.com/seek-oss/vanilla-extract/commit/2f379f118c2a2fe6dc08a1cc15a395dbc0f17ece)]:
|
|
10
|
+
- @vanilla-extract/integration@1.4.2
|
|
11
|
+
|
|
12
|
+
## 2.1.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [#373](https://github.com/seek-oss/vanilla-extract/pull/373) [`a55d2cf`](https://github.com/seek-oss/vanilla-extract/commit/a55d2cfd7c4ca9175a2c86557888df90907bfd0f) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Add `devStyleRuntime` option to allow switching between dev style runtimes
|
|
17
|
+
|
|
18
|
+
The built-in Vite dev style runtime (what adds styles to the page when running `vite serve`) doesn't seem to clean up old styles as expected. Passing `devStyleRuntime: 'vanilla-extract'` will instead use vanilla-extract's browser runtime. This pushes all style creation in development to the browser, but may give a better HMR experience.
|
|
19
|
+
|
|
20
|
+
## 2.0.2
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- [#341](https://github.com/seek-oss/vanilla-extract/pull/341) [`0b743e7`](https://github.com/seek-oss/vanilla-extract/commit/0b743e744447616f8daf0c6b88beff8ffef8d41b) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Refactor SSR file scoping to use centralised `addFileScope` implementation
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [[`50bae14`](https://github.com/seek-oss/vanilla-extract/commit/50bae14bf38c8a971ad1727cb8e827c86da06772), [`0b743e7`](https://github.com/seek-oss/vanilla-extract/commit/0b743e744447616f8daf0c6b88beff8ffef8d41b)]:
|
|
27
|
+
- @vanilla-extract/integration@1.3.0
|
|
28
|
+
|
|
29
|
+
## 2.0.1
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- [#327](https://github.com/seek-oss/vanilla-extract/pull/327) [`73b55f8`](https://github.com/seek-oss/vanilla-extract/commit/73b55f8e7e205701abdb1cbb029c3f2f5080b6fd) Thanks [@benjervis](https://github.com/benjervis)! - Fix bug where precompiled .css.ts files (.css.js) were treated differently in SSR mode.
|
|
34
|
+
|
|
3
35
|
## 2.0.0
|
|
4
36
|
|
|
5
37
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ export const exampleStyle = style({
|
|
|
56
56
|
});
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
> 💡
|
|
59
|
+
> 💡 Once you've [configured your build tooling,](#setup) these `.css.ts` files will be evaluated at build time. None of the code in these files will be included in your final bundle. Think of it as using TypeScript as your preprocessor instead of Sass, Less, etc.
|
|
60
60
|
|
|
61
61
|
**Then consume them in your markup.**
|
|
62
62
|
|
|
@@ -74,7 +74,7 @@ document.write(`
|
|
|
74
74
|
|
|
75
75
|
---
|
|
76
76
|
|
|
77
|
-
Want to work at a higher level while maximising style re-use? Check out 🍨 [Sprinkles](https://
|
|
77
|
+
Want to work at a higher level while maximising style re-use? Check out 🍨 [Sprinkles](https://vanilla-extract.style/documentation/sprinkles-api), our official zero-runtime atomic CSS framework, built on top of vanilla-extract.
|
|
78
78
|
|
|
79
79
|
---
|
|
80
80
|
|
|
@@ -83,6 +83,7 @@ Want to work at a higher level while maximising style re-use? Check out 🍨 [S
|
|
|
83
83
|
- [esbuild](#esbuild)
|
|
84
84
|
- [Vite](#vite)
|
|
85
85
|
- [Snowpack](#snowpack)
|
|
86
|
+
- [Next.js](#nextjs)
|
|
86
87
|
- [Gatsby](#gatsby)
|
|
87
88
|
- [Test environments](#test-environments)
|
|
88
89
|
- [Configuration](#configuration)
|
|
@@ -91,7 +92,6 @@ Want to work at a higher level while maximising style re-use? Check out 🍨 [S
|
|
|
91
92
|
- [style](#style)
|
|
92
93
|
- [styleVariants](#stylevariants)
|
|
93
94
|
- [globalStyle](#globalstyle)
|
|
94
|
-
- [composeStyles](#composestyles)
|
|
95
95
|
- [createTheme](#createtheme)
|
|
96
96
|
- [createGlobalTheme](#createglobaltheme)
|
|
97
97
|
- [createThemeContract](#createthemecontract)
|
|
@@ -102,6 +102,8 @@ Want to work at a higher level while maximising style re-use? Check out 🍨 [S
|
|
|
102
102
|
- [globalFontFace](#globalfontface)
|
|
103
103
|
- [keyframes](#keyframes)
|
|
104
104
|
- [globalKeyframes](#globalkeyframes)
|
|
105
|
+
- [Recipes API](#recipes-api)
|
|
106
|
+
- [recipe](#recipe)
|
|
105
107
|
- [Dynamic API](#dynamic-api)
|
|
106
108
|
- [assignInlineVars](#assigninlinevars)
|
|
107
109
|
- [setElementVars](#setelementvars)
|
|
@@ -121,18 +123,10 @@ There are currently a few integrations to choose from.
|
|
|
121
123
|
1. Install the dependencies.
|
|
122
124
|
|
|
123
125
|
```bash
|
|
124
|
-
npm install @vanilla-extract/css @vanilla-extract/
|
|
126
|
+
npm install @vanilla-extract/css @vanilla-extract/webpack-plugin
|
|
125
127
|
```
|
|
126
128
|
|
|
127
|
-
2. Add the [
|
|
128
|
-
|
|
129
|
-
```json
|
|
130
|
-
{
|
|
131
|
-
"plugins": ["@vanilla-extract/babel-plugin"]
|
|
132
|
-
}
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
3. Add the [webpack](https://webpack.js.org) plugin.
|
|
129
|
+
2. Add the [webpack](https://webpack.js.org) plugin.
|
|
136
130
|
|
|
137
131
|
> 💡 This plugin accepts an optional [configuration object](#configuration).
|
|
138
132
|
|
|
@@ -179,6 +173,18 @@ module.exports = {
|
|
|
179
173
|
```
|
|
180
174
|
</details>
|
|
181
175
|
|
|
176
|
+
3. If you'd like automatic debuggable identifiers, you can add the [Babel](https://babeljs.io) plugin.
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
$ npm install @vanilla-extract/babel-plugin
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```json
|
|
183
|
+
{
|
|
184
|
+
"plugins": ["@vanilla-extract/babel-plugin"]
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
182
188
|
### esbuild
|
|
183
189
|
|
|
184
190
|
1. Install the dependencies.
|
|
@@ -286,6 +292,55 @@ npm install @vanilla-extract/css @vanilla-extract/snowpack-plugin
|
|
|
286
292
|
|
|
287
293
|
> Please note: There are currently no automatic readable class names during development. However, you can still manually provide a debug ID as the last argument to functions that generate scoped styles, e.g. `export const className = style({ ... }, 'className');`
|
|
288
294
|
|
|
295
|
+
### Next.js
|
|
296
|
+
|
|
297
|
+
1. Install the dependencies.
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
npm install @vanilla-extract/css @vanilla-extract/babel-plugin @vanilla-extract/next-plugin
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
2. If you don't have a `.babelrc` file in the root of your project, create one. Add the [Babel](https://babeljs.io) plugin to your `.babelrc` file, ensuring that you're also including `"next/babel"` in your `presets` array.
|
|
304
|
+
|
|
305
|
+
```json
|
|
306
|
+
{
|
|
307
|
+
"presets": ["next/babel"],
|
|
308
|
+
"plugins": ["@vanilla-extract/babel-plugin"]
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
3. If you don't have a `next.config.js` file in the root of your project, create one. Add the [Next.js](https://nextjs.org) plugin to your `next.config.js` file.
|
|
313
|
+
|
|
314
|
+
> 💡 This plugin accepts an optional [configuration object](#configuration).
|
|
315
|
+
|
|
316
|
+
```js
|
|
317
|
+
const {
|
|
318
|
+
createVanillaExtractPlugin
|
|
319
|
+
} = require('@vanilla-extract/next-plugin');
|
|
320
|
+
const withVanillaExtract = createVanillaExtractPlugin();
|
|
321
|
+
|
|
322
|
+
const nextConfig = {};
|
|
323
|
+
|
|
324
|
+
module.exports = withVanillaExtract(nextConfig);
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
If required, this plugin can be composed with other plugins.
|
|
328
|
+
|
|
329
|
+
```js
|
|
330
|
+
const {
|
|
331
|
+
createVanillaExtractPlugin
|
|
332
|
+
} = require('@vanilla-extract/next-plugin');
|
|
333
|
+
const withVanillaExtract = createVanillaExtractPlugin();
|
|
334
|
+
|
|
335
|
+
const withMDX = require('@next/mdx')({
|
|
336
|
+
extension: /\.mdx$/
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
const nextConfig = {};
|
|
340
|
+
|
|
341
|
+
module.exports = withVanillaExtract(withMDX(nextConfig));
|
|
342
|
+
```
|
|
343
|
+
|
|
289
344
|
### Gatsby
|
|
290
345
|
|
|
291
346
|
To add to your [Gatsby](https://www.gatsbyjs.com) site, use the [gatsby-plugin-vanilla-extract](https://github.com/KyleAMathews/gatsby-plugin-vanilla-extract) plugin.
|
|
@@ -393,11 +448,51 @@ export const childClass = style({
|
|
|
393
448
|
});
|
|
394
449
|
```
|
|
395
450
|
|
|
396
|
-
> 💡 To improve maintainability, each
|
|
451
|
+
> 💡 To improve maintainability, each style block can only target a single element. To enforce this, all selectors must target the “&” character which is a reference to the current element.
|
|
452
|
+
>
|
|
453
|
+
> For example, `'&:hover:not(:active)'` and `` [`${parentClass} &`] `` are considered valid, while `'& a[href]'` and `` [`& ${childClass}`] `` are not.
|
|
454
|
+
>
|
|
455
|
+
> If you want to target another scoped class then it should be defined within the style block of that class instead.
|
|
397
456
|
>
|
|
398
|
-
>
|
|
457
|
+
> For example, `` [`& ${childClass}`] `` is invalid since it doesn’t target “&”, so it should instead be defined in the style block for `childClass`.
|
|
399
458
|
>
|
|
400
|
-
>If you want to globally target child nodes within the current element (e.g. `'&
|
|
459
|
+
> If you want to globally target child nodes within the current element (e.g. `'& a[href]'`), you should use [`globalStyle`](#globalstyle) instead.
|
|
460
|
+
|
|
461
|
+
Multiple styles can be composed into a single rule by providing an array of styles.
|
|
462
|
+
|
|
463
|
+
```ts
|
|
464
|
+
import { style } from '@vanilla-extract/css';
|
|
465
|
+
|
|
466
|
+
const base = style({ padding: 12 });
|
|
467
|
+
|
|
468
|
+
export const primary = style([
|
|
469
|
+
base,
|
|
470
|
+
{ background: 'blue' }
|
|
471
|
+
]);
|
|
472
|
+
|
|
473
|
+
export const secondary = style([
|
|
474
|
+
base,
|
|
475
|
+
{ background: 'aqua' }
|
|
476
|
+
]);
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
When composed styles are used in selectors, they are assigned an additional class if required so they can be uniquely identified. When selectors are processed internally, the composed classes are removed, only leaving behind the unique identifier classes. This allows you to treat them as if they were a single class within vanilla-extract selectors.
|
|
480
|
+
|
|
481
|
+
```ts
|
|
482
|
+
import {
|
|
483
|
+
style,
|
|
484
|
+
globalStyle,
|
|
485
|
+
} from '@vanilla-extract/css';
|
|
486
|
+
|
|
487
|
+
const background = style({ background: 'mintcream' });
|
|
488
|
+
const padding = style({ padding: 12 });
|
|
489
|
+
|
|
490
|
+
export const container = style([background, padding]);
|
|
491
|
+
|
|
492
|
+
globalStyle(`${container} *`, {
|
|
493
|
+
boxSizing: 'border-box'
|
|
494
|
+
});
|
|
495
|
+
```
|
|
401
496
|
|
|
402
497
|
### styleVariants
|
|
403
498
|
|
|
@@ -414,20 +509,35 @@ export const variant = styleVariants({
|
|
|
414
509
|
|
|
415
510
|
> 💡 This is useful for mapping component props to styles, e.g. `<button className={styles.variant[props.variant]}>`
|
|
416
511
|
|
|
512
|
+
Multiple styles can be composed into a single rule by providing an array of styles.
|
|
513
|
+
|
|
514
|
+
```ts
|
|
515
|
+
import { styleVariants } from '@vanilla-extract/css';
|
|
516
|
+
|
|
517
|
+
const base = style({ padding: 12 });
|
|
518
|
+
|
|
519
|
+
export const variant = styleVariants({
|
|
520
|
+
primary: [base, { background: 'blue' }],
|
|
521
|
+
secondary: [base, { background: 'aqua' }],
|
|
522
|
+
});
|
|
523
|
+
```
|
|
524
|
+
|
|
417
525
|
You can also transform the values by providing a map function as the second argument.
|
|
418
526
|
|
|
419
527
|
```ts
|
|
420
528
|
import { styleVariants } from '@vanilla-extract/css';
|
|
421
529
|
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
530
|
+
const base = style({ padding: 12 });
|
|
531
|
+
|
|
532
|
+
const backgrounds = {
|
|
533
|
+
primary: 'blue',
|
|
534
|
+
secondary: 'aqua'
|
|
535
|
+
} as const;
|
|
427
536
|
|
|
428
|
-
export const
|
|
429
|
-
|
|
430
|
-
}
|
|
537
|
+
export const variant = styleVariants(
|
|
538
|
+
backgrounds,
|
|
539
|
+
(background) => [base, { background }]
|
|
540
|
+
);
|
|
431
541
|
```
|
|
432
542
|
|
|
433
543
|
### globalStyle
|
|
@@ -445,7 +555,7 @@ globalStyle('html, body', {
|
|
|
445
555
|
Global selectors can also contain references to other scoped class names.
|
|
446
556
|
|
|
447
557
|
```ts
|
|
448
|
-
import { globalStyle } from '@vanilla-extract/css';
|
|
558
|
+
import { style, globalStyle } from '@vanilla-extract/css';
|
|
449
559
|
|
|
450
560
|
export const parentClass = style({});
|
|
451
561
|
|
|
@@ -454,50 +564,6 @@ globalStyle(`${parentClass} > a`, {
|
|
|
454
564
|
});
|
|
455
565
|
```
|
|
456
566
|
|
|
457
|
-
### composeStyles
|
|
458
|
-
|
|
459
|
-
Combines multiple styles into a single class string, while also deduplicating and removing unnecessary spaces.
|
|
460
|
-
|
|
461
|
-
```ts
|
|
462
|
-
import { style, composeStyles } from '@vanilla-extract/css';
|
|
463
|
-
|
|
464
|
-
const button = style({
|
|
465
|
-
padding: 12,
|
|
466
|
-
borderRadius: 8
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
export const primaryButton = composeStyles(
|
|
470
|
-
button,
|
|
471
|
-
style({ background: 'coral' })
|
|
472
|
-
);
|
|
473
|
-
|
|
474
|
-
export const secondaryButton = composeStyles(
|
|
475
|
-
button,
|
|
476
|
-
style({ background: 'peachpuff' })
|
|
477
|
-
);
|
|
478
|
-
```
|
|
479
|
-
|
|
480
|
-
> 💡 Styles can also be provided in shallow and deeply nested arrays, similar to [classnames.](https://github.com/JedWatson/classnames)
|
|
481
|
-
|
|
482
|
-
When style compositions are used in selectors, they are assigned an additional class so they can be uniquely identified. When selectors are processed internally, the composed classes are removed, only leaving behind the unique identifier classes. This allows you to treat them as if they were a single class within vanilla-extract selectors.
|
|
483
|
-
|
|
484
|
-
```ts
|
|
485
|
-
import {
|
|
486
|
-
style,
|
|
487
|
-
globalStyle,
|
|
488
|
-
composeStyles
|
|
489
|
-
} from '@vanilla-extract/css';
|
|
490
|
-
|
|
491
|
-
const background = style({ background: 'mintcream' });
|
|
492
|
-
const padding = style({ padding: 12 });
|
|
493
|
-
|
|
494
|
-
export const container = composeStyles(background, padding);
|
|
495
|
-
|
|
496
|
-
globalStyle(`${container} *`, {
|
|
497
|
-
boxSizing: 'border-box'
|
|
498
|
-
});
|
|
499
|
-
```
|
|
500
|
-
|
|
501
567
|
### createTheme
|
|
502
568
|
|
|
503
569
|
Creates a locally scoped theme class and a theme contract which can be consumed within your styles.
|
|
@@ -683,10 +749,7 @@ For example, you can automatically prefix all variable names.
|
|
|
683
749
|
```ts
|
|
684
750
|
// themes.css.ts
|
|
685
751
|
|
|
686
|
-
import {
|
|
687
|
-
createGlobalThemeContract,
|
|
688
|
-
createGlobalTheme
|
|
689
|
-
} from '@vanilla-extract/css';
|
|
752
|
+
import { createGlobalThemeContract } from '@vanilla-extract/css';
|
|
690
753
|
|
|
691
754
|
export const vars = createGlobalThemeContract({
|
|
692
755
|
color: {
|
|
@@ -703,10 +766,7 @@ You can also use the map function to automatically generate names from the objec
|
|
|
703
766
|
```ts
|
|
704
767
|
// themes.css.ts
|
|
705
768
|
|
|
706
|
-
import {
|
|
707
|
-
createGlobalThemeContract,
|
|
708
|
-
createGlobalTheme
|
|
709
|
-
} from '@vanilla-extract/css';
|
|
769
|
+
import { createGlobalThemeContract } from '@vanilla-extract/css';
|
|
710
770
|
|
|
711
771
|
export const vars = createGlobalThemeContract({
|
|
712
772
|
color: {
|
|
@@ -852,8 +912,8 @@ Creates a locally scoped set of keyframes.
|
|
|
852
912
|
import { keyframes, style } from '@vanilla-extract/css';
|
|
853
913
|
|
|
854
914
|
const rotate = keyframes({
|
|
855
|
-
'0%': {
|
|
856
|
-
'100%': {
|
|
915
|
+
'0%': { transform: 'rotate(0deg)' },
|
|
916
|
+
'100%': { transform: 'rotate(360deg)' }
|
|
857
917
|
});
|
|
858
918
|
|
|
859
919
|
export const animated = style({
|
|
@@ -869,8 +929,8 @@ Creates a globally scoped set of keyframes.
|
|
|
869
929
|
import { globalKeyframes, style } from '@vanilla-extract/css';
|
|
870
930
|
|
|
871
931
|
globalKeyframes('rotate', {
|
|
872
|
-
'0%': {
|
|
873
|
-
'100%': {
|
|
932
|
+
'0%': { transform: 'rotate(0deg)' },
|
|
933
|
+
'100%': { transform: 'rotate(360deg)' }
|
|
874
934
|
});
|
|
875
935
|
|
|
876
936
|
export const animated = style({
|
|
@@ -878,9 +938,117 @@ export const animated = style({
|
|
|
878
938
|
});
|
|
879
939
|
```
|
|
880
940
|
|
|
941
|
+
## Recipes API
|
|
942
|
+
|
|
943
|
+
Create multi-variant styles with a type-safe runtime API, heavily inspired by [Stitches.](https://stitches.dev)
|
|
944
|
+
|
|
945
|
+
As with the rest of vanilla-extract, all styles are generated at build time.
|
|
946
|
+
|
|
947
|
+
```bash
|
|
948
|
+
$ npm install @vanilla-extract/recipes
|
|
949
|
+
```
|
|
950
|
+
|
|
951
|
+
### recipe
|
|
952
|
+
|
|
953
|
+
Creates a multi-variant style function that can be used at runtime or statically in `.css.ts` files.
|
|
954
|
+
|
|
955
|
+
Accepts an optional set of `base` styles, `variants`, `compoundVariants` and `defaultVariants`.
|
|
956
|
+
|
|
957
|
+
```ts
|
|
958
|
+
import { recipe } from '@vanilla-extract/recipes';
|
|
959
|
+
|
|
960
|
+
export const button = recipe({
|
|
961
|
+
base: {
|
|
962
|
+
borderRadius: 6
|
|
963
|
+
},
|
|
964
|
+
|
|
965
|
+
variants: {
|
|
966
|
+
color: {
|
|
967
|
+
neutral: { background: 'whitesmoke' },
|
|
968
|
+
brand: { background: 'blueviolet' },
|
|
969
|
+
accent: { background: 'slateblue' }
|
|
970
|
+
},
|
|
971
|
+
size: {
|
|
972
|
+
small: { padding: 12 },
|
|
973
|
+
medium: { padding: 16 },
|
|
974
|
+
large: { padding: 24 }
|
|
975
|
+
},
|
|
976
|
+
rounded: {
|
|
977
|
+
true: { borderRadius: 999 }
|
|
978
|
+
}
|
|
979
|
+
},
|
|
980
|
+
|
|
981
|
+
// Applied when multiple variants are set at once
|
|
982
|
+
compoundVariants: [
|
|
983
|
+
{
|
|
984
|
+
variants: {
|
|
985
|
+
color: 'neutral',
|
|
986
|
+
size: 'large'
|
|
987
|
+
},
|
|
988
|
+
style: {
|
|
989
|
+
background: 'ghostwhite'
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
],
|
|
993
|
+
|
|
994
|
+
defaultVariants: {
|
|
995
|
+
color: 'accent',
|
|
996
|
+
size: 'medium'
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
```
|
|
1000
|
+
|
|
1001
|
+
With this recipe configured, you can now use it in your templates.
|
|
1002
|
+
|
|
1003
|
+
```ts
|
|
1004
|
+
import { button } from './button.css.ts';
|
|
1005
|
+
|
|
1006
|
+
document.write(`
|
|
1007
|
+
<button class="${button({
|
|
1008
|
+
color: 'accent',
|
|
1009
|
+
size: 'large',
|
|
1010
|
+
rounded: true
|
|
1011
|
+
})}">
|
|
1012
|
+
Hello world
|
|
1013
|
+
</button>
|
|
1014
|
+
`);
|
|
1015
|
+
```
|
|
1016
|
+
|
|
1017
|
+
Your recipe configuration can also make use of existing variables, classes and styles.
|
|
1018
|
+
|
|
1019
|
+
For example, you can pass in the result of your [`sprinkles`](https://vanilla-extract.style/documentation/sprinkles-api) function directly.
|
|
1020
|
+
|
|
1021
|
+
```ts
|
|
1022
|
+
import { recipe } from '@vanilla-extract/recipes';
|
|
1023
|
+
import { reset } from './reset.css.ts';
|
|
1024
|
+
import { sprinkles } from './sprinkles.css.ts';
|
|
1025
|
+
|
|
1026
|
+
export const button = recipe({
|
|
1027
|
+
base: [reset, sprinkles({ borderRadius: 'round' })],
|
|
1028
|
+
|
|
1029
|
+
variants: {
|
|
1030
|
+
color: {
|
|
1031
|
+
neutral: sprinkles({ background: 'neutral' }),
|
|
1032
|
+
brand: sprinkles({ background: 'brand' }),
|
|
1033
|
+
accent: sprinkles({ background: 'accent' })
|
|
1034
|
+
},
|
|
1035
|
+
size: {
|
|
1036
|
+
small: sprinkles({ padding: 'small' }),
|
|
1037
|
+
medium: sprinkles({ padding: 'medium' }),
|
|
1038
|
+
large: sprinkles({ padding: 'large' })
|
|
1039
|
+
}
|
|
1040
|
+
},
|
|
1041
|
+
|
|
1042
|
+
defaultVariants: {
|
|
1043
|
+
color: 'accent',
|
|
1044
|
+
size: 'medium'
|
|
1045
|
+
}
|
|
1046
|
+
});
|
|
1047
|
+
```
|
|
1048
|
+
|
|
881
1049
|
## Dynamic API
|
|
882
1050
|
|
|
883
|
-
|
|
1051
|
+
Dynamically update theme variables at runtime.
|
|
884
1052
|
|
|
885
1053
|
```bash
|
|
886
1054
|
npm install @vanilla-extract/dynamic
|
|
@@ -2,6 +2,11 @@ import type { Plugin } from 'vite';
|
|
|
2
2
|
import { IdentifierOption } from '@vanilla-extract/integration';
|
|
3
3
|
interface Options {
|
|
4
4
|
identifiers?: IdentifierOption;
|
|
5
|
+
/**
|
|
6
|
+
* Which CSS runtime to use when running `vite serve`.
|
|
7
|
+
* @default 'vite'
|
|
8
|
+
*/
|
|
9
|
+
devStyleRuntime?: 'vite' | 'vanilla-extract';
|
|
5
10
|
}
|
|
6
|
-
export declare function vanillaExtractPlugin({ identifiers }?: Options): Plugin;
|
|
11
|
+
export declare function vanillaExtractPlugin({ identifiers, devStyleRuntime, }?: Options): Plugin;
|
|
7
12
|
export {};
|
|
@@ -11,10 +11,12 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
11
11
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
12
|
|
|
13
13
|
function vanillaExtractPlugin({
|
|
14
|
-
identifiers
|
|
14
|
+
identifiers,
|
|
15
|
+
devStyleRuntime = 'vite'
|
|
15
16
|
} = {}) {
|
|
16
17
|
let config;
|
|
17
18
|
let packageInfo;
|
|
19
|
+
let useRuntime = false;
|
|
18
20
|
const cssMap = new Map();
|
|
19
21
|
return {
|
|
20
22
|
name: 'vanilla-extract',
|
|
@@ -22,6 +24,7 @@ function vanillaExtractPlugin({
|
|
|
22
24
|
|
|
23
25
|
configResolved(resolvedConfig) {
|
|
24
26
|
config = resolvedConfig;
|
|
27
|
+
useRuntime = devStyleRuntime === 'vanilla-extract' && config.command === 'serve';
|
|
25
28
|
packageInfo = integration.getPackageInfo(config.root);
|
|
26
29
|
},
|
|
27
30
|
|
|
@@ -54,16 +57,12 @@ function vanillaExtractPlugin({
|
|
|
54
57
|
return null;
|
|
55
58
|
}
|
|
56
59
|
|
|
57
|
-
if (ssr
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
${code}
|
|
65
|
-
endFileScope();
|
|
66
|
-
`;
|
|
60
|
+
if (ssr || useRuntime) {
|
|
61
|
+
return integration.addFileScope({
|
|
62
|
+
source: code,
|
|
63
|
+
filePath: vite.normalizePath(path__default['default'].relative(packageInfo.dirname, id)),
|
|
64
|
+
packageInfo
|
|
65
|
+
}).source;
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
const {
|
|
@@ -11,10 +11,12 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
11
11
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
12
|
|
|
13
13
|
function vanillaExtractPlugin({
|
|
14
|
-
identifiers
|
|
14
|
+
identifiers,
|
|
15
|
+
devStyleRuntime = 'vite'
|
|
15
16
|
} = {}) {
|
|
16
17
|
let config;
|
|
17
18
|
let packageInfo;
|
|
19
|
+
let useRuntime = false;
|
|
18
20
|
const cssMap = new Map();
|
|
19
21
|
return {
|
|
20
22
|
name: 'vanilla-extract',
|
|
@@ -22,6 +24,7 @@ function vanillaExtractPlugin({
|
|
|
22
24
|
|
|
23
25
|
configResolved(resolvedConfig) {
|
|
24
26
|
config = resolvedConfig;
|
|
27
|
+
useRuntime = devStyleRuntime === 'vanilla-extract' && config.command === 'serve';
|
|
25
28
|
packageInfo = integration.getPackageInfo(config.root);
|
|
26
29
|
},
|
|
27
30
|
|
|
@@ -54,16 +57,12 @@ function vanillaExtractPlugin({
|
|
|
54
57
|
return null;
|
|
55
58
|
}
|
|
56
59
|
|
|
57
|
-
if (ssr
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
${code}
|
|
65
|
-
endFileScope();
|
|
66
|
-
`;
|
|
60
|
+
if (ssr || useRuntime) {
|
|
61
|
+
return integration.addFileScope({
|
|
62
|
+
source: code,
|
|
63
|
+
filePath: vite.normalizePath(path__default['default'].relative(packageInfo.dirname, id)),
|
|
64
|
+
packageInfo
|
|
65
|
+
}).source;
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
const {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { normalizePath } from 'vite';
|
|
3
|
-
import { getPackageInfo, virtualCssFileFilter, getSourceFromVirtualCssFile, hash, cssFileFilter, compile, processVanillaFile } from '@vanilla-extract/integration';
|
|
3
|
+
import { getPackageInfo, virtualCssFileFilter, getSourceFromVirtualCssFile, hash, cssFileFilter, addFileScope, compile, processVanillaFile } from '@vanilla-extract/integration';
|
|
4
4
|
|
|
5
5
|
function vanillaExtractPlugin({
|
|
6
|
-
identifiers
|
|
6
|
+
identifiers,
|
|
7
|
+
devStyleRuntime = 'vite'
|
|
7
8
|
} = {}) {
|
|
8
9
|
let config;
|
|
9
10
|
let packageInfo;
|
|
11
|
+
let useRuntime = false;
|
|
10
12
|
const cssMap = new Map();
|
|
11
13
|
return {
|
|
12
14
|
name: 'vanilla-extract',
|
|
@@ -14,6 +16,7 @@ function vanillaExtractPlugin({
|
|
|
14
16
|
|
|
15
17
|
configResolved(resolvedConfig) {
|
|
16
18
|
config = resolvedConfig;
|
|
19
|
+
useRuntime = devStyleRuntime === 'vanilla-extract' && config.command === 'serve';
|
|
17
20
|
packageInfo = getPackageInfo(config.root);
|
|
18
21
|
},
|
|
19
22
|
|
|
@@ -46,16 +49,12 @@ function vanillaExtractPlugin({
|
|
|
46
49
|
return null;
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
if (ssr
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
${code}
|
|
57
|
-
endFileScope();
|
|
58
|
-
`;
|
|
52
|
+
if (ssr || useRuntime) {
|
|
53
|
+
return addFileScope({
|
|
54
|
+
source: code,
|
|
55
|
+
filePath: normalizePath(path.relative(packageInfo.dirname, id)),
|
|
56
|
+
packageInfo
|
|
57
|
+
}).source;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
const {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanilla-extract/vite-plugin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Zero-runtime Stylesheets-in-TypeScript",
|
|
5
5
|
"main": "dist/vanilla-extract-vite-plugin.cjs.js",
|
|
6
6
|
"module": "dist/vanilla-extract-vite-plugin.esm.js",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"author": "SEEK",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@vanilla-extract/integration": "^1.2
|
|
18
|
+
"@vanilla-extract/integration": "^1.4.2"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"vite": "^2.
|
|
21
|
+
"vite": "^2.6.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"vite": "^2.2.3"
|