Skip to content

Commit 691db3a

Browse files
committed
Build with Vite
Vite is a significantly faster builder than Webpack which the JS ecosystem seems to be adopting widely. We're already using for Compound Web, and Storybook makes it pretty simple to swap it out for Webpack, so that's what I've done here.
1 parent 414369b commit 691db3a

File tree

7 files changed

+2740
-1913
lines changed

7 files changed

+2740
-1913
lines changed

.storybook/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default {
2828
],
2929
staticDirs: ["../public"],
3030
framework: {
31-
name: "@storybook/react-webpack5",
31+
name: "@storybook/react-vite",
3232
options: {},
3333
},
3434
docs: {

.storybook/preview-head.html

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
<style>
2-
/*
3-
CSS for Storybook Docs
4-
*/
5-
</style>
1+
<link rel="stylesheet" href="/global.css" />

.storybook/preview.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
import React from "react";
1818

19-
import "!style-loader!css-loader!@vector-im/compound-design-tokens/assets/web/css/compound-design-tokens.css";
20-
import "!style-loader!css-loader!../public/global.css";
19+
import "@vector-im/compound-design-tokens/assets/web/css/compound-design-tokens.css";
2120

2221
// import { Body, H1, H2, H3, H4, H5, H6 } from "@vector-im/compound-web";
2322

package.json

+12-11
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
"@babel/preset-env": "^7.20.2",
2323
"@babel/preset-react": "^7.18.6",
2424
"@babel/preset-typescript": "^7.21.5",
25-
"@storybook/addon-actions": "^7.0.11",
26-
"@storybook/addon-essentials": "^7.0.11",
27-
"@storybook/addon-interactions": "^7.0.11",
28-
"@storybook/addon-links": "^7.0.11",
29-
"@storybook/addon-mdx-gfm": "^7.0.11",
30-
"@storybook/manager-api": "^7.0.11",
31-
"@storybook/react": "^7.0.11",
32-
"@storybook/react-webpack5": "^7.0.11",
25+
"@storybook/addon-actions": "^7.6.12",
26+
"@storybook/addon-essentials": "^7.6.12",
27+
"@storybook/addon-interactions": "^7.6.12",
28+
"@storybook/addon-links": "^7.6.12",
29+
"@storybook/addon-mdx-gfm": "^7.6.12",
30+
"@storybook/manager-api": "^7.6.12",
31+
"@storybook/react": "^7.6.12",
32+
"@storybook/react-vite": "^7.6.12",
3333
"@storybook/testing-library": "^0.1.0",
34-
"@storybook/theming": "^7.0.11",
34+
"@storybook/theming": "^7.6.12",
3535
"babel-loader": "^9.1.2",
3636
"chokidar-cli": "^3.0.0",
3737
"eslint": "^8.32.0",
@@ -41,11 +41,12 @@
4141
"lodash": "^4.17.21",
4242
"prettier": "^2.8.3",
4343
"sharp": "^0.31.0",
44-
"storybook": "^7.0.11",
44+
"storybook": "^7.6.12",
4545
"style-dictionary": "^3.7.1",
4646
"svg2vectordrawable": "^2.9.1",
4747
"tinycolor2": "^1.4.2",
48-
"typescript": "^5.0.4"
48+
"typescript": "^5.0.4",
49+
"vite": "^5.0.12"
4950
},
5051
"dependencies": {
5152
"@vector-im/compound-design-tokens": "https://github.com/vector-im/compound-design-tokens#0.1.0",

stories/src/utils/Icon.tsx

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
import React from "react";
1+
import React, { useEffect, useState } from "react";
22

3-
export const Icon: React.FC<{iconName: string}> = ({ iconName }) => {
4-
return <div className="cpdIconItem">
5-
<img className="cpdIcon" alt={iconName} src={require(`@vector-im/compound-design-tokens/icons/${iconName}.svg`)}/>
6-
<p>{iconName}</p>
3+
const icons = import.meta.glob(
4+
`../../../node_modules/@vector-im/compound-design-tokens/icons/*.svg`
5+
);
6+
7+
export const Icon: React.FC<{ iconName: string }> = ({ iconName }) => {
8+
const [src, setSrc] = useState<string | undefined>(undefined);
9+
useEffect(() => {
10+
icons[
11+
`../../../node_modules/@vector-im/compound-design-tokens/icons/${iconName}.svg`
12+
]().then((src) => setSrc((src as { default: string }).default));
13+
}, [iconName]);
14+
15+
return (
16+
<div className="cpdIconItem">
17+
<img className="cpdIcon" alt={iconName} src={src} />
18+
<p>{iconName}</p>
719
</div>
8-
}
20+
);
21+
};

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"jsx": "react",
1010

1111
/* Modules */
12-
"module": "commonjs" /* Specify what module code is generated. */,
12+
"module": "es2022" /* Specify what module code is generated. */,
1313

1414
/* Emit */
1515
"declaration": true,
@@ -23,6 +23,7 @@
2323
/* Type Checking */
2424
"strict": true /* Enable all strict type-checking options. */,
2525
"rootDir": "./",
26+
"types": ["vite/client"],
2627

2728
/* Completeness */
2829
"skipLibCheck": true /* Skip type checking all .d.ts files. */

0 commit comments

Comments
 (0)