├── README.md
├── babel.config.js
├── .gitignore
├── stories
├── EnvironmentVariables.stories.jsx
├── EnvironmentVariables.jsx
├── Header.stories.jsx
├── Page.stories.jsx
├── header.css
├── Button.stories.jsx
├── button.css
├── assets
│ ├── direction.svg
│ ├── flow.svg
│ ├── code-brackets.svg
│ ├── comments.svg
│ ├── repo.svg
│ ├── plugin.svg
│ ├── stackalt.svg
│ └── colors.svg
├── page.css
├── Button.jsx
├── Header.jsx
├── Page.jsx
└── Introduction.stories.mdx
├── .storybook
└── main.js
└── package.json
/README.md:
--------------------------------------------------------------------------------
1 | # example-storybook-vite-babel-error
2 | Example of storybook with vite and babel error
3 |
4 | ## Reproduction
5 |
6 | ```
7 | yarn
8 | yarn build-storybook
9 | ```
10 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [
3 | ["@babel/preset-env", { targets: { node: "current" } }],
4 | "@babel/preset-typescript",
5 | "@babel/preset-react",
6 | ],
7 | };
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | storybook-static
3 | .idea
4 |
5 |
6 | # Yarn stuff
7 | /**/.yarn/*
8 | !/**/.yarn/releases
9 | !/**/.yarn/plugins
10 | !/**/.yarn/sdks
11 | !/**/.yarn/versions
12 | /**/.pnp.*
13 | .DS_STORE
14 |
--------------------------------------------------------------------------------
/stories/EnvironmentVariables.stories.jsx:
--------------------------------------------------------------------------------
1 | import {EnvironmentVariables} from './EnvironmentVariables';
2 |
3 | export default {
4 | title: 'Environment Variables',
5 | component: EnvironmentVariables
6 | };
7 |
8 | export const Info = () => ;
9 |
--------------------------------------------------------------------------------
/stories/EnvironmentVariables.jsx:
--------------------------------------------------------------------------------
1 |
2 | export function EnvironmentVariables() {
3 | return (
4 |
5 |
import . meta . env:
6 |
{JSON.stringify(import.meta.env, null, 2)}
7 |
import . meta . env . STORYBOOK:
8 |
{import.meta.env.STORYBOOK}
9 |
10 | )
11 | }
12 |
--------------------------------------------------------------------------------
/stories/Header.stories.jsx:
--------------------------------------------------------------------------------
1 | import { Header } from './Header';
2 |
3 | export default {
4 | title: 'Example/Header',
5 | component: Header,
6 | };
7 |
8 | const Template = (args) => ;
9 |
10 | export const LoggedIn = Template.bind({});
11 | LoggedIn.args = {
12 | user: {},
13 | };
14 |
15 | export const LoggedOut = Template.bind({});
16 | LoggedOut.args = {};
17 |
--------------------------------------------------------------------------------
/stories/Page.stories.jsx:
--------------------------------------------------------------------------------
1 | import { Page } from './Page';
2 | import * as HeaderStories from './Header.stories';
3 |
4 | export default {
5 | title: 'Example/Page',
6 | component: Page,
7 | };
8 |
9 | const Template = (args) => ;
10 |
11 | export const LoggedIn = Template.bind({});
12 | LoggedIn.args = {
13 | ...HeaderStories.LoggedIn.args,
14 | };
15 |
16 | export const LoggedOut = Template.bind({});
17 | LoggedOut.args = {
18 | ...HeaderStories.LoggedOut.args,
19 | };
20 |
--------------------------------------------------------------------------------
/stories/header.css:
--------------------------------------------------------------------------------
1 | .wrapper {
2 | font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
3 | border-bottom: 1px solid rgba(0, 0, 0, 0.1);
4 | padding: 15px 20px;
5 | display: flex;
6 | align-items: center;
7 | justify-content: space-between;
8 | }
9 |
10 | svg {
11 | display: inline-block;
12 | vertical-align: top;
13 | }
14 |
15 | h1 {
16 | font-weight: 900;
17 | font-size: 20px;
18 | line-height: 1;
19 | margin: 6px 0 6px 10px;
20 | display: inline-block;
21 | vertical-align: top;
22 | }
23 |
24 | button + button {
25 | margin-left: 10px;
26 | }
27 |
--------------------------------------------------------------------------------
/.storybook/main.js:
--------------------------------------------------------------------------------
1 | const macrosPlugin = require("vite-plugin-babel-macros");
2 |
3 | module.exports = {
4 | stories: [
5 | "../stories/**/*.stories.mdx",
6 | "../stories/**/*.stories.@(js|jsx|ts|tsx)",
7 | ],
8 | addons: [
9 | "@storybook/addon-a11y",
10 | "@storybook/addon-links",
11 | "@storybook/addon-essentials",
12 | ],
13 | core: {
14 | builder: "storybook-builder-vite",
15 | },
16 | async viteFinal(config, { configType }) {
17 | // customize the Vite config here
18 | config.plugins = [...(config.plugins ?? []), macrosPlugin.default()];
19 |
20 | return config;
21 | },
22 | };
23 |
--------------------------------------------------------------------------------
/stories/Button.stories.jsx:
--------------------------------------------------------------------------------
1 | import { Button } from './Button';
2 |
3 | export default {
4 | title: 'Example/Button',
5 | component: Button,
6 | argTypes: {
7 | backgroundColor: { control: 'color' },
8 | },
9 | };
10 |
11 | const Template = (args) => ;
12 |
13 | export const Primary = Template.bind({});
14 | Primary.args = {
15 | primary: true,
16 | label: 'Button',
17 | };
18 |
19 | export const Secondary = Template.bind({});
20 | Secondary.args = {
21 | label: 'Button',
22 | };
23 |
24 | export const Large = Template.bind({});
25 | Large.args = {
26 | size: 'large',
27 | label: 'Button',
28 | };
29 |
30 | export const Small = Template.bind({});
31 | Small.args = {
32 | size: 'small',
33 | label: 'Button',
34 | };
35 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example-storybook-vite-babel-error",
3 | "private": true,
4 | "version": "0.0.0",
5 | "description": "",
6 | "main": "index.js",
7 | "scripts": {
8 | "storybook": "start-storybook",
9 | "build-storybook": "build-storybook"
10 | },
11 | "author": "",
12 | "license": "MIT",
13 | "dependencies": {
14 | "react": "17.0.2",
15 | "react-dom": "17.0.2"
16 | },
17 | "devDependencies": {
18 | "@storybook/addon-a11y": "6.3.11",
19 | "@storybook/addon-docs": "6.3.11",
20 | "@storybook/addon-essentials": "6.3.11",
21 | "@storybook/react": "6.3.11",
22 | "storybook-builder-vite": "0.1.1",
23 | "vite": "2.6.7",
24 | "vite-plugin-babel-macros": "1.0.5"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/stories/button.css:
--------------------------------------------------------------------------------
1 | .storybook-button {
2 | font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
3 | font-weight: 700;
4 | border: 0;
5 | border-radius: 3em;
6 | cursor: pointer;
7 | display: inline-block;
8 | line-height: 1;
9 | }
10 | .storybook-button--primary {
11 | color: white;
12 | background-color: #1ea7fd;
13 | }
14 | .storybook-button--secondary {
15 | color: #333;
16 | background-color: transparent;
17 | box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset;
18 | }
19 | .storybook-button--small {
20 | font-size: 12px;
21 | padding: 10px 16px;
22 | }
23 | .storybook-button--medium {
24 | font-size: 14px;
25 | padding: 11px 20px;
26 | }
27 | .storybook-button--large {
28 | font-size: 16px;
29 | padding: 12px 24px;
30 | }
31 |
--------------------------------------------------------------------------------
/stories/assets/direction.svg:
--------------------------------------------------------------------------------
1 | illustration/direction
--------------------------------------------------------------------------------
/stories/assets/flow.svg:
--------------------------------------------------------------------------------
1 | illustration/flow
--------------------------------------------------------------------------------
/stories/page.css:
--------------------------------------------------------------------------------
1 | section {
2 | font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
3 | font-size: 14px;
4 | line-height: 24px;
5 | padding: 48px 20px;
6 | margin: 0 auto;
7 | max-width: 600px;
8 | color: #333;
9 | }
10 |
11 | h2 {
12 | font-weight: 900;
13 | font-size: 32px;
14 | line-height: 1;
15 | margin: 0 0 4px;
16 | display: inline-block;
17 | vertical-align: top;
18 | }
19 |
20 | p {
21 | margin: 1em 0;
22 | }
23 |
24 | a {
25 | text-decoration: none;
26 | color: #1ea7fd;
27 | }
28 |
29 | ul {
30 | padding-left: 30px;
31 | margin: 1em 0;
32 | }
33 |
34 | li {
35 | margin-bottom: 8px;
36 | }
37 |
38 | .tip {
39 | display: inline-block;
40 | border-radius: 1em;
41 | font-size: 11px;
42 | line-height: 12px;
43 | font-weight: 700;
44 | background: #e7fdd8;
45 | color: #66bf3c;
46 | padding: 4px 12px;
47 | margin-right: 10px;
48 | vertical-align: top;
49 | }
50 |
51 | .tip-wrapper {
52 | font-size: 13px;
53 | line-height: 20px;
54 | margin-top: 40px;
55 | margin-bottom: 40px;
56 | }
57 |
58 | .tip-wrapper svg {
59 | display: inline-block;
60 | height: 12px;
61 | width: 12px;
62 | margin-right: 4px;
63 | vertical-align: top;
64 | margin-top: 3px;
65 | }
66 |
67 | .tip-wrapper svg path {
68 | fill: #1ea7fd;
69 | }
70 |
--------------------------------------------------------------------------------
/stories/assets/code-brackets.svg:
--------------------------------------------------------------------------------
1 | illustration/code-brackets
--------------------------------------------------------------------------------
/stories/Button.jsx:
--------------------------------------------------------------------------------
1 | import PropTypes from 'prop-types';
2 | import './button.css';
3 |
4 | /**
5 | * Primary UI component for user interaction
6 | */
7 | export const Button = ({ primary, backgroundColor, size, label, ...props }) => {
8 | const mode = primary
9 | ? 'storybook-button--primary'
10 | : 'storybook-button--secondary';
11 | return (
12 |
22 | {label}
23 |
24 | );
25 | };
26 |
27 | Button.propTypes = {
28 | /**
29 | * Is this the principal call to action on the page?
30 | */
31 | primary: PropTypes.bool,
32 | /**
33 | * What background color to use
34 | */
35 | backgroundColor: PropTypes.string,
36 | /**
37 | * How large should the button be?
38 | */
39 | size: PropTypes.oneOf(['small', 'medium', 'large']),
40 | /**
41 | * Button contents
42 | */
43 | label: PropTypes.string.isRequired,
44 | /**
45 | * Optional click handler
46 | */
47 | onClick: PropTypes.func,
48 | };
49 |
50 | Button.defaultProps = {
51 | backgroundColor: null,
52 | primary: false,
53 | size: 'medium',
54 | onClick: undefined,
55 | };
56 |
--------------------------------------------------------------------------------
/stories/assets/comments.svg:
--------------------------------------------------------------------------------
1 | illustration/comments
--------------------------------------------------------------------------------
/stories/assets/repo.svg:
--------------------------------------------------------------------------------
1 | illustration/repo
--------------------------------------------------------------------------------
/stories/assets/plugin.svg:
--------------------------------------------------------------------------------
1 | illustration/plugin
--------------------------------------------------------------------------------
/stories/Header.jsx:
--------------------------------------------------------------------------------
1 | import PropTypes from 'prop-types';
2 |
3 | import { Button } from './Button';
4 | import './header.css';
5 |
6 | export const Header = ({ user, onLogin, onLogout, onCreateAccount }) => (
7 |
50 | );
51 |
52 | Header.propTypes = {
53 | user: PropTypes.shape({}),
54 | onLogin: PropTypes.func.isRequired,
55 | onLogout: PropTypes.func.isRequired,
56 | onCreateAccount: PropTypes.func.isRequired,
57 | };
58 |
59 | Header.defaultProps = {
60 | user: null,
61 | };
62 |
--------------------------------------------------------------------------------
/stories/assets/stackalt.svg:
--------------------------------------------------------------------------------
1 | illustration/stackalt
--------------------------------------------------------------------------------
/stories/Page.jsx:
--------------------------------------------------------------------------------
1 | import PropTypes from 'prop-types';
2 |
3 | import { Header } from './Header';
4 | import './page.css';
5 |
6 | export const Page = ({ user, onLogin, onLogout, onCreateAccount }) => (
7 |
8 |
14 |
15 |
16 | Pages in Storybook
17 |
18 | We recommend building UIs with a{' '}
19 |
24 | component-driven
25 | {' '}
26 | process starting with atomic components and ending with pages.
27 |
28 |
29 | Render pages with mock data. This makes it easy to build and
30 | review page states without needing to navigate to them in your
31 | app. Here are some handy patterns for managing page data in
32 | Storybook:
33 |
34 |
35 |
36 | Use a higher-level connected component. Storybook helps you
37 | compose such data from the "args" of child component stories
38 |
39 |
40 | Assemble data in the page component from your services. You
41 | can mock these services out using Storybook.
42 |
43 |
44 |
45 | Get a guided tutorial on component-driven development at{' '}
46 |
51 | Storybook tutorials
52 |
53 | . Read more in the{' '}
54 |
59 | docs
60 |
61 | .
62 |
63 |
64 |
Tip Adjust the width of the canvas
65 | with the{' '}
66 |
72 |
73 |
78 |
79 |
80 | Viewports addon in the toolbar
81 |
82 |
83 |
84 | );
85 | Page.propTypes = {
86 | user: PropTypes.shape({}),
87 | onLogin: PropTypes.func.isRequired,
88 | onLogout: PropTypes.func.isRequired,
89 | onCreateAccount: PropTypes.func.isRequired,
90 | };
91 |
92 | Page.defaultProps = {
93 | user: null,
94 | };
95 |
--------------------------------------------------------------------------------
/stories/Introduction.stories.mdx:
--------------------------------------------------------------------------------
1 | import { Meta } from '@storybook/addon-docs';
2 | import Code from './assets/code-brackets.svg';
3 | import Colors from './assets/colors.svg';
4 | import Comments from './assets/comments.svg';
5 | import Direction from './assets/direction.svg';
6 | import Flow from './assets/flow.svg';
7 | import Plugin from './assets/plugin.svg';
8 | import Repo from './assets/repo.svg';
9 | import StackAlt from './assets/stackalt.svg';
10 |
11 |
12 |
13 |
116 |
117 | # Welcome to Storybook
118 |
119 | Storybook helps you build UI components in isolation from your app's business logic, data, and context.
120 | That makes it easy to develop hard-to-reach states. Save these UI states as **stories** to revisit during development, testing, or QA.
121 |
122 | Browse example stories now by navigating to them in the sidebar.
123 | View their code in the `src/stories` directory to learn how they work.
124 | We recommend building UIs with a [**component-driven**](https://componentdriven.org) process starting with atomic components and ending with pages.
125 |
126 | Configure
127 |
128 |
174 |
175 | Learn
176 |
177 |
223 |
224 |
225 | Tip Edit the Markdown in{' '}
226 | src/stories/Introduction.stories.mdx
227 |
228 |
--------------------------------------------------------------------------------
/stories/assets/colors.svg:
--------------------------------------------------------------------------------
1 | illustration/colors
--------------------------------------------------------------------------------