@vanilla-extract/vite-plugin 1.2.0 → 2.1.0
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 +47 -0
- package/README.md +371 -75
- package/dist/declarations/src/index.d.ts +11 -1
- package/dist/vanilla-extract-vite-plugin.cjs.dev.js +14 -12
- package/dist/vanilla-extract-vite-plugin.cjs.prod.js +14 -12
- package/dist/vanilla-extract-vite-plugin.esm.js +15 -13
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# @vanilla-extract/vite-plugin
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
## 2.0.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#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
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`50bae14`](https://github.com/seek-oss/vanilla-extract/commit/50bae14bf38c8a971ad1727cb8e827c86da06772), [`0b743e7`](https://github.com/seek-oss/vanilla-extract/commit/0b743e744447616f8daf0c6b88beff8ffef8d41b)]:
|
|
18
|
+
- @vanilla-extract/integration@1.3.0
|
|
19
|
+
|
|
20
|
+
## 2.0.1
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- [#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.
|
|
25
|
+
|
|
26
|
+
## 2.0.0
|
|
27
|
+
|
|
28
|
+
### Major Changes
|
|
29
|
+
|
|
30
|
+
- [#323](https://github.com/seek-oss/vanilla-extract/pull/323) [`1e7d647`](https://github.com/seek-oss/vanilla-extract/commit/1e7d6470398a0fbcbdef4118e678150932cd9275) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc) can now be configured via the `identifiers` option which accepts either `short` or `debug`.
|
|
31
|
+
|
|
32
|
+
- `short` identifiers are a 7+ character hash. e.g. `hnw5tz3`
|
|
33
|
+
- `debug` identifiers contain human readable prefixes representing the owning filename and a potential rule level debug name. e.g. `somefile_mystyle_hnw5tz3`
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
|
|
37
|
+
|
|
38
|
+
vanillaExtractPlugin({ identifiers: 'short' });
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
BREAKING CHANGE
|
|
42
|
+
|
|
43
|
+
Previously identifiers were formatted as `short` when `process.env.NODE_ENV` was set to "production". By default, they will now be formatted according to Vite's [mode config](https://vitejs.dev/config/#mode).
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- Updated dependencies [[`1e7d647`](https://github.com/seek-oss/vanilla-extract/commit/1e7d6470398a0fbcbdef4118e678150932cd9275)]:
|
|
48
|
+
- @vanilla-extract/integration@1.2.0
|
|
49
|
+
|
|
3
50
|
## 1.2.0
|
|
4
51
|
|
|
5
52
|
### Minor 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,13 +83,15 @@ 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)
|
|
89
|
+
- [Configuration](#configuration)
|
|
90
|
+
- [identifiers](#identifiers)
|
|
88
91
|
- [Styling API](#styling-api)
|
|
89
92
|
- [style](#style)
|
|
90
93
|
- [styleVariants](#stylevariants)
|
|
91
94
|
- [globalStyle](#globalstyle)
|
|
92
|
-
- [composeStyles](#composestyles)
|
|
93
95
|
- [createTheme](#createtheme)
|
|
94
96
|
- [createGlobalTheme](#createglobaltheme)
|
|
95
97
|
- [createThemeContract](#createthemecontract)
|
|
@@ -100,6 +102,8 @@ Want to work at a higher level while maximising style re-use? Check out 🍨 [S
|
|
|
100
102
|
- [globalFontFace](#globalfontface)
|
|
101
103
|
- [keyframes](#keyframes)
|
|
102
104
|
- [globalKeyframes](#globalkeyframes)
|
|
105
|
+
- [Recipes API](#recipes-api)
|
|
106
|
+
- [recipe](#recipe)
|
|
103
107
|
- [Dynamic API](#dynamic-api)
|
|
104
108
|
- [assignInlineVars](#assigninlinevars)
|
|
105
109
|
- [setElementVars](#setelementvars)
|
|
@@ -119,18 +123,12 @@ There are currently a few integrations to choose from.
|
|
|
119
123
|
1. Install the dependencies.
|
|
120
124
|
|
|
121
125
|
```bash
|
|
122
|
-
npm install @vanilla-extract/css @vanilla-extract/
|
|
126
|
+
npm install @vanilla-extract/css @vanilla-extract/webpack-plugin
|
|
123
127
|
```
|
|
124
128
|
|
|
125
|
-
2. Add the [
|
|
126
|
-
|
|
127
|
-
```json
|
|
128
|
-
{
|
|
129
|
-
"plugins": ["@vanilla-extract/babel-plugin"]
|
|
130
|
-
}
|
|
131
|
-
```
|
|
129
|
+
2. Add the [webpack](https://webpack.js.org) plugin.
|
|
132
130
|
|
|
133
|
-
|
|
131
|
+
> 💡 This plugin accepts an optional [configuration object](#configuration).
|
|
134
132
|
|
|
135
133
|
```js
|
|
136
134
|
const { VanillaExtractPlugin } = require('@vanilla-extract/webpack-plugin');
|
|
@@ -175,6 +173,18 @@ module.exports = {
|
|
|
175
173
|
```
|
|
176
174
|
</details>
|
|
177
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
|
+
|
|
178
188
|
### esbuild
|
|
179
189
|
|
|
180
190
|
1. Install the dependencies.
|
|
@@ -185,6 +195,8 @@ npm install @vanilla-extract/css @vanilla-extract/esbuild-plugin
|
|
|
185
195
|
|
|
186
196
|
2. Add the [esbuild](https://esbuild.github.io/) plugin to your build script.
|
|
187
197
|
|
|
198
|
+
> 💡 This plugin accepts an optional [configuration object](#configuration).
|
|
199
|
+
|
|
188
200
|
```js
|
|
189
201
|
const { vanillaExtractPlugin } = require('@vanilla-extract/esbuild-plugin');
|
|
190
202
|
|
|
@@ -246,6 +258,8 @@ npm install @vanilla-extract/css @vanilla-extract/vite-plugin
|
|
|
246
258
|
|
|
247
259
|
2. Add the [Vite](https://vitejs.dev/) plugin to your Vite config.
|
|
248
260
|
|
|
261
|
+
> 💡 This plugin accepts an optional [configuration object](#configuration).
|
|
262
|
+
|
|
249
263
|
```js
|
|
250
264
|
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
|
|
251
265
|
|
|
@@ -267,6 +281,8 @@ npm install @vanilla-extract/css @vanilla-extract/snowpack-plugin
|
|
|
267
281
|
|
|
268
282
|
2. Add the [Snowpack](https://www.snowpack.dev/) plugin to your snowpack config.
|
|
269
283
|
|
|
284
|
+
> 💡 This plugin accepts an optional [configuration object](#configuration).
|
|
285
|
+
|
|
270
286
|
```js
|
|
271
287
|
// snowpack.config.json
|
|
272
288
|
{
|
|
@@ -276,6 +292,55 @@ npm install @vanilla-extract/css @vanilla-extract/snowpack-plugin
|
|
|
276
292
|
|
|
277
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');`
|
|
278
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
|
+
|
|
279
344
|
### Gatsby
|
|
280
345
|
|
|
281
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.
|
|
@@ -305,6 +370,16 @@ In testing environments (like `jsdom`) vanilla-extract will create and insert st
|
|
|
305
370
|
import '@vanilla-extract/css/disableRuntimeStyles';
|
|
306
371
|
```
|
|
307
372
|
|
|
373
|
+
### Configuration
|
|
374
|
+
|
|
375
|
+
#### identifiers
|
|
376
|
+
|
|
377
|
+
Different formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc) can be configured by selecting from the following options:
|
|
378
|
+
|
|
379
|
+
- `short` identifiers are a 7+ character hash. e.g. `hnw5tz3`
|
|
380
|
+
- `debug` identifiers contain human readable prefixes representing the owning filename and a potential rule level debug name. e.g. `myfile_mystyle_hnw5tz3`
|
|
381
|
+
|
|
382
|
+
Each integration will set a default value based on the configuration options passed to the bundler.
|
|
308
383
|
|
|
309
384
|
---
|
|
310
385
|
|
|
@@ -373,11 +448,51 @@ export const childClass = style({
|
|
|
373
448
|
});
|
|
374
449
|
```
|
|
375
450
|
|
|
376
|
-
> 💡 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.
|
|
377
454
|
>
|
|
378
|
-
>If you want to target another scoped class then it should be defined within the
|
|
455
|
+
> If you want to target another scoped class then it should be defined within the style block of that class instead.
|
|
379
456
|
>
|
|
380
|
-
>
|
|
457
|
+
> For example, `` [`& ${childClass}`] `` is invalid since it doesn’t target “&”, so it should instead be defined in the style block for `childClass`.
|
|
458
|
+
>
|
|
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
|
+
```
|
|
381
496
|
|
|
382
497
|
### styleVariants
|
|
383
498
|
|
|
@@ -394,20 +509,35 @@ export const variant = styleVariants({
|
|
|
394
509
|
|
|
395
510
|
> 💡 This is useful for mapping component props to styles, e.g. `<button className={styles.variant[props.variant]}>`
|
|
396
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
|
+
|
|
397
525
|
You can also transform the values by providing a map function as the second argument.
|
|
398
526
|
|
|
399
527
|
```ts
|
|
400
528
|
import { styleVariants } from '@vanilla-extract/css';
|
|
401
529
|
|
|
402
|
-
const
|
|
403
|
-
small: 4,
|
|
404
|
-
medium: 8,
|
|
405
|
-
large: 16
|
|
406
|
-
};
|
|
530
|
+
const base = style({ padding: 12 });
|
|
407
531
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
532
|
+
const backgrounds = {
|
|
533
|
+
primary: 'blue',
|
|
534
|
+
secondary: 'aqua'
|
|
535
|
+
} as const;
|
|
536
|
+
|
|
537
|
+
export const variant = styleVariants(
|
|
538
|
+
backgrounds,
|
|
539
|
+
(background) => [base, { background }]
|
|
540
|
+
);
|
|
411
541
|
```
|
|
412
542
|
|
|
413
543
|
### globalStyle
|
|
@@ -425,7 +555,7 @@ globalStyle('html, body', {
|
|
|
425
555
|
Global selectors can also contain references to other scoped class names.
|
|
426
556
|
|
|
427
557
|
```ts
|
|
428
|
-
import { globalStyle } from '@vanilla-extract/css';
|
|
558
|
+
import { style, globalStyle } from '@vanilla-extract/css';
|
|
429
559
|
|
|
430
560
|
export const parentClass = style({});
|
|
431
561
|
|
|
@@ -434,54 +564,12 @@ globalStyle(`${parentClass} > a`, {
|
|
|
434
564
|
});
|
|
435
565
|
```
|
|
436
566
|
|
|
437
|
-
### composeStyles
|
|
438
|
-
|
|
439
|
-
Combines multiple styles into a single class string, while also deduplicating and removing unnecessary spaces.
|
|
440
|
-
|
|
441
|
-
```ts
|
|
442
|
-
import { style, composeStyles } from '@vanilla-extract/css';
|
|
443
|
-
|
|
444
|
-
const button = style({
|
|
445
|
-
padding: 12,
|
|
446
|
-
borderRadius: 8
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
export const primaryButton = composeStyles(
|
|
450
|
-
button,
|
|
451
|
-
style({ background: 'coral' })
|
|
452
|
-
);
|
|
453
|
-
|
|
454
|
-
export const secondaryButton = composeStyles(
|
|
455
|
-
button,
|
|
456
|
-
style({ background: 'peachpuff' })
|
|
457
|
-
);
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
> 💡 Styles can also be provided in shallow and deeply nested arrays, similar to [classnames.](https://github.com/JedWatson/classnames)
|
|
461
|
-
|
|
462
|
-
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.
|
|
463
|
-
|
|
464
|
-
```ts
|
|
465
|
-
import {
|
|
466
|
-
style,
|
|
467
|
-
globalStyle,
|
|
468
|
-
composeStyles
|
|
469
|
-
} from '@vanilla-extract/css';
|
|
470
|
-
|
|
471
|
-
const background = style({ background: 'mintcream' });
|
|
472
|
-
const padding = style({ padding: 12 });
|
|
473
|
-
|
|
474
|
-
export const container = composeStyles(background, padding);
|
|
475
|
-
|
|
476
|
-
globalStyle(`${container} *`, {
|
|
477
|
-
boxSizing: 'border-box'
|
|
478
|
-
});
|
|
479
|
-
```
|
|
480
|
-
|
|
481
567
|
### createTheme
|
|
482
568
|
|
|
483
569
|
Creates a locally scoped theme class and a theme contract which can be consumed within your styles.
|
|
484
570
|
|
|
571
|
+
**Ensure this function is called within a `.css.ts` context, otherwise variable names will be mismatched between files.**
|
|
572
|
+
|
|
485
573
|
```ts
|
|
486
574
|
// theme.css.ts
|
|
487
575
|
|
|
@@ -529,6 +617,8 @@ export const themeB = createTheme(vars, {
|
|
|
529
617
|
|
|
530
618
|
Creates a theme attached to a global selector, but with locally scoped variable names.
|
|
531
619
|
|
|
620
|
+
**Ensure this function is called within a `.css.ts` context, otherwise variable names will be mismatched between files.**
|
|
621
|
+
|
|
532
622
|
```ts
|
|
533
623
|
// theme.css.ts
|
|
534
624
|
|
|
@@ -546,11 +636,40 @@ export const vars = createGlobalTheme(':root', {
|
|
|
546
636
|
|
|
547
637
|
> 💡 All theme variants must provide a value for every variable or it’s a type error.
|
|
548
638
|
|
|
639
|
+
If you want to implement an existing theme contract, you can pass it as the second argument.
|
|
640
|
+
|
|
641
|
+
```ts
|
|
642
|
+
// theme.css.ts
|
|
643
|
+
|
|
644
|
+
import {
|
|
645
|
+
createThemeContract,
|
|
646
|
+
createGlobalTheme
|
|
647
|
+
} from '@vanilla-extract/css';
|
|
648
|
+
|
|
649
|
+
export const vars = createThemeContract({
|
|
650
|
+
color: {
|
|
651
|
+
brand: null
|
|
652
|
+
},
|
|
653
|
+
font: {
|
|
654
|
+
body: null
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
createGlobalTheme(':root', vars, {
|
|
659
|
+
color: {
|
|
660
|
+
brand: 'blue'
|
|
661
|
+
},
|
|
662
|
+
font: {
|
|
663
|
+
body: 'arial'
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
```
|
|
667
|
+
|
|
549
668
|
### createThemeContract
|
|
550
669
|
|
|
551
|
-
Creates a contract for themes to implement.
|
|
670
|
+
Creates a contract of locally scoped variable names for themes to implement.
|
|
552
671
|
|
|
553
|
-
**Ensure this function is called within a `.css.ts` context, otherwise variable names will be mismatched between
|
|
672
|
+
**Ensure this function is called within a `.css.ts` context, otherwise variable names will be mismatched between files.**
|
|
554
673
|
|
|
555
674
|
> 💡 This is useful if you want to split your themes into different bundles. In this case, your themes would be defined in separate files, but we'll keep this example simple.
|
|
556
675
|
|
|
@@ -590,6 +709,75 @@ export const themeB = createTheme(vars, {
|
|
|
590
709
|
});
|
|
591
710
|
```
|
|
592
711
|
|
|
712
|
+
### createGlobalThemeContract
|
|
713
|
+
|
|
714
|
+
Creates a contract of globally scoped variable names for themes to implement.
|
|
715
|
+
|
|
716
|
+
> 💡 This is useful if you want to make your theme contract available to non-JavaScript environments.
|
|
717
|
+
|
|
718
|
+
```ts
|
|
719
|
+
// themes.css.ts
|
|
720
|
+
|
|
721
|
+
import {
|
|
722
|
+
createGlobalThemeContract,
|
|
723
|
+
createGlobalTheme
|
|
724
|
+
} from '@vanilla-extract/css';
|
|
725
|
+
|
|
726
|
+
export const vars = createGlobalThemeContract({
|
|
727
|
+
color: {
|
|
728
|
+
brand: 'color-brand'
|
|
729
|
+
},
|
|
730
|
+
font: {
|
|
731
|
+
body: 'font-body'
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
createGlobalTheme(':root', vars, {
|
|
736
|
+
color: {
|
|
737
|
+
brand: 'blue'
|
|
738
|
+
},
|
|
739
|
+
font: {
|
|
740
|
+
body: 'arial'
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
You can also provide a map function as the second argument which has access to the value and the object path.
|
|
746
|
+
|
|
747
|
+
For example, you can automatically prefix all variable names.
|
|
748
|
+
|
|
749
|
+
```ts
|
|
750
|
+
// themes.css.ts
|
|
751
|
+
|
|
752
|
+
import { createGlobalThemeContract } from '@vanilla-extract/css';
|
|
753
|
+
|
|
754
|
+
export const vars = createGlobalThemeContract({
|
|
755
|
+
color: {
|
|
756
|
+
brand: 'color-brand'
|
|
757
|
+
},
|
|
758
|
+
font: {
|
|
759
|
+
body: 'font-body'
|
|
760
|
+
}
|
|
761
|
+
}, (value) => `prefix-${value}`);
|
|
762
|
+
```
|
|
763
|
+
|
|
764
|
+
You can also use the map function to automatically generate names from the object path, joining keys with a hyphen.
|
|
765
|
+
|
|
766
|
+
```ts
|
|
767
|
+
// themes.css.ts
|
|
768
|
+
|
|
769
|
+
import { createGlobalThemeContract } from '@vanilla-extract/css';
|
|
770
|
+
|
|
771
|
+
export const vars = createGlobalThemeContract({
|
|
772
|
+
color: {
|
|
773
|
+
brand: null
|
|
774
|
+
},
|
|
775
|
+
font: {
|
|
776
|
+
body: null
|
|
777
|
+
}
|
|
778
|
+
}, (_value, path) => `prefix-${path.join('-')}`);
|
|
779
|
+
```
|
|
780
|
+
|
|
593
781
|
### assignVars
|
|
594
782
|
|
|
595
783
|
Assigns a collection of CSS Variables anywhere within a style block.
|
|
@@ -724,8 +912,8 @@ Creates a locally scoped set of keyframes.
|
|
|
724
912
|
import { keyframes, style } from '@vanilla-extract/css';
|
|
725
913
|
|
|
726
914
|
const rotate = keyframes({
|
|
727
|
-
'0%': {
|
|
728
|
-
'100%': {
|
|
915
|
+
'0%': { transform: 'rotate(0deg)' },
|
|
916
|
+
'100%': { transform: 'rotate(360deg)' }
|
|
729
917
|
});
|
|
730
918
|
|
|
731
919
|
export const animated = style({
|
|
@@ -741,8 +929,8 @@ Creates a globally scoped set of keyframes.
|
|
|
741
929
|
import { globalKeyframes, style } from '@vanilla-extract/css';
|
|
742
930
|
|
|
743
931
|
globalKeyframes('rotate', {
|
|
744
|
-
'0%': {
|
|
745
|
-
'100%': {
|
|
932
|
+
'0%': { transform: 'rotate(0deg)' },
|
|
933
|
+
'100%': { transform: 'rotate(360deg)' }
|
|
746
934
|
});
|
|
747
935
|
|
|
748
936
|
export const animated = style({
|
|
@@ -750,9 +938,117 @@ export const animated = style({
|
|
|
750
938
|
});
|
|
751
939
|
```
|
|
752
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
|
+
|
|
753
1049
|
## Dynamic API
|
|
754
1050
|
|
|
755
|
-
|
|
1051
|
+
Dynamically update theme variables at runtime.
|
|
756
1052
|
|
|
757
1053
|
```bash
|
|
758
1054
|
npm install @vanilla-extract/dynamic
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
|
|
2
|
+
import { IdentifierOption } from '@vanilla-extract/integration';
|
|
3
|
+
interface Options {
|
|
4
|
+
identifiers?: IdentifierOption;
|
|
5
|
+
/**
|
|
6
|
+
* Which CSS runtime to use when running `vite serve`.
|
|
7
|
+
* @default 'vite'
|
|
8
|
+
*/
|
|
9
|
+
devStyleRuntime?: 'vite' | 'vanilla-extract';
|
|
10
|
+
}
|
|
11
|
+
export declare function vanillaExtractPlugin({ identifiers, devStyleRuntime, }?: Options): Plugin;
|
|
12
|
+
export {};
|
|
@@ -10,9 +10,13 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
10
10
|
|
|
11
11
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
12
|
|
|
13
|
-
function vanillaExtractPlugin(
|
|
13
|
+
function vanillaExtractPlugin({
|
|
14
|
+
identifiers,
|
|
15
|
+
devStyleRuntime = 'vite'
|
|
16
|
+
} = {}) {
|
|
14
17
|
let config;
|
|
15
18
|
let packageInfo;
|
|
19
|
+
let useRuntime = false;
|
|
16
20
|
const cssMap = new Map();
|
|
17
21
|
return {
|
|
18
22
|
name: 'vanilla-extract',
|
|
@@ -20,6 +24,7 @@ function vanillaExtractPlugin() {
|
|
|
20
24
|
|
|
21
25
|
configResolved(resolvedConfig) {
|
|
22
26
|
config = resolvedConfig;
|
|
27
|
+
useRuntime = devStyleRuntime === 'vanilla-extract' && config.command === 'serve';
|
|
23
28
|
packageInfo = integration.getPackageInfo(config.root);
|
|
24
29
|
},
|
|
25
30
|
|
|
@@ -52,16 +57,12 @@ function vanillaExtractPlugin() {
|
|
|
52
57
|
return null;
|
|
53
58
|
}
|
|
54
59
|
|
|
55
|
-
if (ssr
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
${code}
|
|
63
|
-
endFileScope();
|
|
64
|
-
`;
|
|
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;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
const {
|
|
@@ -79,7 +80,8 @@ function vanillaExtractPlugin() {
|
|
|
79
80
|
return integration.processVanillaFile({
|
|
80
81
|
source,
|
|
81
82
|
filePath: id,
|
|
82
|
-
outputCss: !ssr
|
|
83
|
+
outputCss: !ssr,
|
|
84
|
+
identOption: identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug'
|
|
83
85
|
});
|
|
84
86
|
}
|
|
85
87
|
|
|
@@ -10,9 +10,13 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
10
10
|
|
|
11
11
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
12
|
|
|
13
|
-
function vanillaExtractPlugin(
|
|
13
|
+
function vanillaExtractPlugin({
|
|
14
|
+
identifiers,
|
|
15
|
+
devStyleRuntime = 'vite'
|
|
16
|
+
} = {}) {
|
|
14
17
|
let config;
|
|
15
18
|
let packageInfo;
|
|
19
|
+
let useRuntime = false;
|
|
16
20
|
const cssMap = new Map();
|
|
17
21
|
return {
|
|
18
22
|
name: 'vanilla-extract',
|
|
@@ -20,6 +24,7 @@ function vanillaExtractPlugin() {
|
|
|
20
24
|
|
|
21
25
|
configResolved(resolvedConfig) {
|
|
22
26
|
config = resolvedConfig;
|
|
27
|
+
useRuntime = devStyleRuntime === 'vanilla-extract' && config.command === 'serve';
|
|
23
28
|
packageInfo = integration.getPackageInfo(config.root);
|
|
24
29
|
},
|
|
25
30
|
|
|
@@ -52,16 +57,12 @@ function vanillaExtractPlugin() {
|
|
|
52
57
|
return null;
|
|
53
58
|
}
|
|
54
59
|
|
|
55
|
-
if (ssr
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
${code}
|
|
63
|
-
endFileScope();
|
|
64
|
-
`;
|
|
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;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
const {
|
|
@@ -79,7 +80,8 @@ function vanillaExtractPlugin() {
|
|
|
79
80
|
return integration.processVanillaFile({
|
|
80
81
|
source,
|
|
81
82
|
filePath: id,
|
|
82
|
-
outputCss: !ssr
|
|
83
|
+
outputCss: !ssr,
|
|
84
|
+
identOption: identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug'
|
|
83
85
|
});
|
|
84
86
|
}
|
|
85
87
|
|
|
@@ -1,10 +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
|
-
function vanillaExtractPlugin(
|
|
5
|
+
function vanillaExtractPlugin({
|
|
6
|
+
identifiers,
|
|
7
|
+
devStyleRuntime = 'vite'
|
|
8
|
+
} = {}) {
|
|
6
9
|
let config;
|
|
7
10
|
let packageInfo;
|
|
11
|
+
let useRuntime = false;
|
|
8
12
|
const cssMap = new Map();
|
|
9
13
|
return {
|
|
10
14
|
name: 'vanilla-extract',
|
|
@@ -12,6 +16,7 @@ function vanillaExtractPlugin() {
|
|
|
12
16
|
|
|
13
17
|
configResolved(resolvedConfig) {
|
|
14
18
|
config = resolvedConfig;
|
|
19
|
+
useRuntime = devStyleRuntime === 'vanilla-extract' && config.command === 'serve';
|
|
15
20
|
packageInfo = getPackageInfo(config.root);
|
|
16
21
|
},
|
|
17
22
|
|
|
@@ -44,16 +49,12 @@ function vanillaExtractPlugin() {
|
|
|
44
49
|
return null;
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
if (ssr
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
${code}
|
|
55
|
-
endFileScope();
|
|
56
|
-
`;
|
|
52
|
+
if (ssr || useRuntime) {
|
|
53
|
+
return addFileScope({
|
|
54
|
+
source: code,
|
|
55
|
+
filePath: normalizePath(path.relative(packageInfo.dirname, id)),
|
|
56
|
+
packageInfo
|
|
57
|
+
}).source;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
const {
|
|
@@ -71,7 +72,8 @@ function vanillaExtractPlugin() {
|
|
|
71
72
|
return processVanillaFile({
|
|
72
73
|
source,
|
|
73
74
|
filePath: id,
|
|
74
|
-
outputCss: !ssr
|
|
75
|
+
outputCss: !ssr,
|
|
76
|
+
identOption: identifiers !== null && identifiers !== void 0 ? identifiers : config.mode === 'production' ? 'short' : 'debug'
|
|
75
77
|
});
|
|
76
78
|
}
|
|
77
79
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanilla-extract/vite-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
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,7 +15,7 @@
|
|
|
15
15
|
"author": "SEEK",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@vanilla-extract/integration": "^1.
|
|
18
|
+
"@vanilla-extract/integration": "^1.3.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"vite": "^2.2.3"
|