Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/twelve-suns-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@vanilla-extract/rollup-plugin': minor
---

Add "extract" option which bundles CSS into one bundle. Removes .css imports.

**EXAMPLE USAGE**:
```ts
vanillaExtractPlugin({
extract: {
name: 'bundle.css',
sourcemap: false
}
});
18 changes: 18 additions & 0 deletions fixtures/react-library-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@fixtures/react-library-example",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this fixture because for bundling I really wanted all the following conditions:

  • both global and scoped CSS in the same package
  • some deterministic ordering present (i.e. some CSS is expected to load before other)
  • Vanilla Extract styles used in runtime, which didn’t have to be React, I was just too lazy to use another framework or do some pseudo-HTML template thing

"description": "React design system library",
"version": "0.0.1",
"private": true,
"type": "module",
"main": "./dist/index.js",
"dependencies": {
"@vanilla-extract/css": "workspace:*",
"clsx": "^2.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19"
}
}
11 changes: 11 additions & 0 deletions fixtures/react-library-example/src/button/button.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { style } from '@vanilla-extract/css';
import { vars } from '../styles/vars.css.js';

export const btn = style({
background: vars.color.background.brand,
borderRadius: vars.size.radius[200],
color: vars.color.text.brand,
...vars.typography.body.medium,
paddingBlock: vars.size.space[200],
paddingInline: vars.size.space[300],
});
15 changes: 15 additions & 0 deletions fixtures/react-library-example/src/button/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import clsx from 'clsx';
import * as styles from './button.css.js';

export default function Button({
className,
children,
type = 'button',
...props
}: React.ComponentProps<'button'>) {
return (
<button {...props} type={type} className={clsx(styles.btn, className)}>
{children}
</button>
);
}
22 changes: 22 additions & 0 deletions fixtures/react-library-example/src/checkbox/checkbox.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { style } from '@vanilla-extract/css';
import { vars } from '../styles/vars.css.js';

export const label = style({
display: 'block',
...vars.typography.body.medium,

'::before': {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn’t even look at these styles at all; they’re nonsense. But they’re just here to generate lines of code to test in the final bundle, and pull from the theme

background: vars.color.background.brand,
borderColor: vars.color.border.default,
borderWidth: 1,
borderStyle: 'solid',
content: '',
borderRadius: vars.size.radius['200'],
marginRight: vars.size.space['300'],
},
});

export const input = style({
width: '1.5rem',
height: '1.5rem',
});
25 changes: 25 additions & 0 deletions fixtures/react-library-example/src/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useId } from 'react';
import clsx from 'clsx';
import * as styles from './checkbox.css.js';

export default function Radio({
children,
className,
id,
...props
}: React.ComponentProps<'input'> & { children: React.ReactNode }) {
const randomID = useId();
return (
<>
<input
{...props}
className={styles.input}
id={id ?? randomID}
type="checkbox"
/>
<label className={clsx(styles.label, className)} htmlFor={id ?? randomID}>
{children}
</label>
</>
);
}
10 changes: 10 additions & 0 deletions fixtures/react-library-example/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 1. Style reset
import './styles/reset.css.js';

// 2. Design library
export { default as Button } from './button/button.js';
export { default as Checkbox } from './checkbox/checkbox.js';
export { default as Radio } from './radio/radio.js';

// 3. Utility CSS should be last
import './styles/utility.css.js';
22 changes: 22 additions & 0 deletions fixtures/react-library-example/src/radio/radio.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { style } from '@vanilla-extract/css';
import { vars } from '../styles/vars.css.js';

export const label = style({
display: 'block',
...vars.typography.body.medium,

'::before': {
background: vars.color.background.brand,
borderColor: vars.color.border.default,
borderWidth: 1,
borderStyle: 'solid',
content: '',
borderRadius: vars.size.radius.full,
marginRight: vars.size.space['300'],
},
});

export const input = style({
width: '1.5rem',
height: '1.5rem',
});
25 changes: 25 additions & 0 deletions fixtures/react-library-example/src/radio/radio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useId } from 'react';
import clsx from 'clsx';
import * as styles from './radio.css.js';

export default function Radio({
children,
className,
id,
...props
}: React.ComponentProps<'input'> & { children: React.ReactNode }) {
const randomID = useId();
return (
<>
<input
{...props}
className={styles.input}
id={id ?? randomID}
type="radio"
/>
<label className={clsx(styles.label, className)} htmlFor={id ?? randomID}>
{children}
</label>
</>
);
}
8 changes: 8 additions & 0 deletions fixtures/react-library-example/src/styles/reset.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { globalStyle } from '@vanilla-extract/css';

globalStyle('html, body', {
fontSize: '100%',
height: '100%',
lineHeight: 1,
margin: 0,
});
10 changes: 10 additions & 0 deletions fixtures/react-library-example/src/styles/utility.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { style } from '@vanilla-extract/css';
import { vars } from './vars.css.js';

// Note: these aren’t meant to be intended as best practice over Sprinkles,
// these are only testing style() declarations loaded differently

export const mt100 = style({ marginTop: vars.size.space[100] });
export const mt200 = style({ marginTop: vars.size.space[200] });
export const mt300 = style({ marginTop: vars.size.space[300] });
export const mt400 = style({ marginTop: vars.size.space[400] });
Loading
Loading