@vanilla-extract/vite-plugin 2.0.2 → 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 CHANGED
@@ -1,5 +1,13 @@
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
+
3
11
  ## 2.0.2
4
12
 
5
13
  ### Patch Changes
package/README.md CHANGED
@@ -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://github.com/seek-oss/vanilla-extract/tree/master/packages/sprinkles), our official zero-runtime atomic CSS framework, built on top of vanilla-extract.
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
 
@@ -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)
@@ -553,7 +555,7 @@ globalStyle('html, body', {
553
555
  Global selectors can also contain references to other scoped class names.
554
556
 
555
557
  ```ts
556
- import { globalStyle } from '@vanilla-extract/css';
558
+ import { style, globalStyle } from '@vanilla-extract/css';
557
559
 
558
560
  export const parentClass = style({});
559
561
 
@@ -910,8 +912,8 @@ Creates a locally scoped set of keyframes.
910
912
  import { keyframes, style } from '@vanilla-extract/css';
911
913
 
912
914
  const rotate = keyframes({
913
- '0%': { rotate: '0deg' },
914
- '100%': { rotate: '360deg' },
915
+ '0%': { transform: 'rotate(0deg)' },
916
+ '100%': { transform: 'rotate(360deg)' }
915
917
  });
916
918
 
917
919
  export const animated = style({
@@ -927,8 +929,8 @@ Creates a globally scoped set of keyframes.
927
929
  import { globalKeyframes, style } from '@vanilla-extract/css';
928
930
 
929
931
  globalKeyframes('rotate', {
930
- '0%': { rotate: '0deg' },
931
- '100%': { rotate: '360deg' },
932
+ '0%': { transform: 'rotate(0deg)' },
933
+ '100%': { transform: 'rotate(360deg)' }
932
934
  });
933
935
 
934
936
  export const animated = style({
@@ -936,9 +938,117 @@ export const animated = style({
936
938
  });
937
939
  ```
938
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
+
939
1049
  ## Dynamic API
940
1050
 
941
- We also provide a lightweight standalone package to support dynamic runtime theming.
1051
+ Dynamically update theme variables at runtime.
942
1052
 
943
1053
  ```bash
944
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,7 +57,7 @@ function vanillaExtractPlugin({
54
57
  return null;
55
58
  }
56
59
 
57
- if (ssr) {
60
+ if (ssr || useRuntime) {
58
61
  return integration.addFileScope({
59
62
  source: code,
60
63
  filePath: vite.normalizePath(path__default['default'].relative(packageInfo.dirname, id)),
@@ -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,7 +57,7 @@ function vanillaExtractPlugin({
54
57
  return null;
55
58
  }
56
59
 
57
- if (ssr) {
60
+ if (ssr || useRuntime) {
58
61
  return integration.addFileScope({
59
62
  source: code,
60
63
  filePath: vite.normalizePath(path__default['default'].relative(packageInfo.dirname, id)),
@@ -3,10 +3,12 @@ import { normalizePath } from 'vite';
3
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,7 +49,7 @@ function vanillaExtractPlugin({
46
49
  return null;
47
50
  }
48
51
 
49
- if (ssr) {
52
+ if (ssr || useRuntime) {
50
53
  return addFileScope({
51
54
  source: code,
52
55
  filePath: normalizePath(path.relative(packageInfo.dirname, id)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanilla-extract/vite-plugin",
3
- "version": "2.0.2",
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",