Skip to content

Commit 4a020ba

Browse files
drwpowaskoufis
andauthored
Add "extract" option to Rollup plugin (#1604)
Co-authored-by: Adam Skoufis <[email protected]>
1 parent c907c10 commit 4a020ba

File tree

20 files changed

+1585
-57
lines changed

20 files changed

+1585
-57
lines changed

.changeset/twelve-suns-hope.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@vanilla-extract/rollup-plugin': minor
3+
---
4+
5+
Add "extract" option which bundles CSS into one bundle. Removes .css imports.
6+
7+
**EXAMPLE USAGE**:
8+
```ts
9+
vanillaExtractPlugin({
10+
extract: {
11+
name: 'bundle.css',
12+
sourcemap: false
13+
}
14+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@fixtures/react-library-example",
3+
"description": "React design system library",
4+
"version": "0.0.1",
5+
"private": true,
6+
"type": "module",
7+
"main": "./dist/index.js",
8+
"dependencies": {
9+
"@vanilla-extract/css": "workspace:*",
10+
"clsx": "^2.1.1",
11+
"react": "^18.2.0",
12+
"react-dom": "^18.2.0"
13+
},
14+
"devDependencies": {
15+
"@types/react": "^18.2.55",
16+
"@types/react-dom": "^18.2.19"
17+
}
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { style } from '@vanilla-extract/css';
2+
import { vars } from '../styles/vars.css.js';
3+
4+
export const btn = style({
5+
background: vars.color.background.brand,
6+
borderRadius: vars.size.radius[200],
7+
color: vars.color.text.brand,
8+
...vars.typography.body.medium,
9+
paddingBlock: vars.size.space[200],
10+
paddingInline: vars.size.space[300],
11+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import clsx from 'clsx';
2+
import * as styles from './button.css.js';
3+
4+
export default function Button({
5+
className,
6+
children,
7+
type = 'button',
8+
...props
9+
}: React.ComponentProps<'button'>) {
10+
return (
11+
<button {...props} type={type} className={clsx(styles.btn, className)}>
12+
{children}
13+
</button>
14+
);
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { style } from '@vanilla-extract/css';
2+
import { vars } from '../styles/vars.css.js';
3+
4+
export const label = style({
5+
display: 'block',
6+
...vars.typography.body.medium,
7+
8+
'::before': {
9+
background: vars.color.background.brand,
10+
borderColor: vars.color.border.default,
11+
borderWidth: 1,
12+
borderStyle: 'solid',
13+
content: '',
14+
borderRadius: vars.size.radius['200'],
15+
marginRight: vars.size.space['300'],
16+
},
17+
});
18+
19+
export const input = style({
20+
width: '1.5rem',
21+
height: '1.5rem',
22+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useId } from 'react';
2+
import clsx from 'clsx';
3+
import * as styles from './checkbox.css.js';
4+
5+
export default function Radio({
6+
children,
7+
className,
8+
id,
9+
...props
10+
}: React.ComponentProps<'input'> & { children: React.ReactNode }) {
11+
const randomID = useId();
12+
return (
13+
<>
14+
<input
15+
{...props}
16+
className={styles.input}
17+
id={id ?? randomID}
18+
type="checkbox"
19+
/>
20+
<label className={clsx(styles.label, className)} htmlFor={id ?? randomID}>
21+
{children}
22+
</label>
23+
</>
24+
);
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// 1. Style reset
2+
import './styles/reset.css.js';
3+
4+
// 2. Design library
5+
export { default as Button } from './button/button.js';
6+
export { default as Checkbox } from './checkbox/checkbox.js';
7+
export { default as Radio } from './radio/radio.js';
8+
9+
// 3. Utility CSS should be last
10+
import './styles/utility.css.js';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { style } from '@vanilla-extract/css';
2+
import { vars } from '../styles/vars.css.js';
3+
4+
export const label = style({
5+
display: 'block',
6+
...vars.typography.body.medium,
7+
8+
'::before': {
9+
background: vars.color.background.brand,
10+
borderColor: vars.color.border.default,
11+
borderWidth: 1,
12+
borderStyle: 'solid',
13+
content: '',
14+
borderRadius: vars.size.radius.full,
15+
marginRight: vars.size.space['300'],
16+
},
17+
});
18+
19+
export const input = style({
20+
width: '1.5rem',
21+
height: '1.5rem',
22+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useId } from 'react';
2+
import clsx from 'clsx';
3+
import * as styles from './radio.css.js';
4+
5+
export default function Radio({
6+
children,
7+
className,
8+
id,
9+
...props
10+
}: React.ComponentProps<'input'> & { children: React.ReactNode }) {
11+
const randomID = useId();
12+
return (
13+
<>
14+
<input
15+
{...props}
16+
className={styles.input}
17+
id={id ?? randomID}
18+
type="radio"
19+
/>
20+
<label className={clsx(styles.label, className)} htmlFor={id ?? randomID}>
21+
{children}
22+
</label>
23+
</>
24+
);
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { globalStyle } from '@vanilla-extract/css';
2+
3+
globalStyle('html, body', {
4+
fontSize: '100%',
5+
height: '100%',
6+
lineHeight: 1,
7+
margin: 0,
8+
});

0 commit comments

Comments
 (0)