-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26266 from storybookjs/framework-doc-vue3-webpack5
Docs: Add `vue3-webpack5` framework doc
- Loading branch information
Showing
9 changed files
with
232 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,3 @@ | ||
# Storybook for Vue 3 and Webpack | ||
|
||
Storybook for Vue 3 is a UI development environment for your Vue 3 components. | ||
With it, you can visualize different states of your UI components and develop them interactively. | ||
|
||
![Storybook Screenshot](https://github.com/storybookjs/storybook/blob/main/media/storybook-intro.gif) | ||
|
||
Storybook runs outside of your app. | ||
So you can develop UI components in isolation without worrying about app specific dependencies and requirements. | ||
|
||
## Getting Started | ||
|
||
```sh | ||
cd my-vue3-app | ||
npx storybook@latest init | ||
``` | ||
|
||
For more information visit: [storybook.js.org](https://storybook.js.org) | ||
|
||
--- | ||
|
||
Storybook also comes with a lot of [addons](https://storybook.js.org/addons) and a great API to customize as you wish. | ||
You can also build a [static version](https://storybook.js.org/docs/sharing/publish-storybook) of your Storybook and deploy it anywhere you want. | ||
|
||
## Extending the Vue application | ||
|
||
Storybook creates a [Vue 3 application](https://vuejs.org/api/application.html#application-api) for your component preview. | ||
When using global custom components (`app.component`), directives (`app.directive`), extensions (`app.use`), or other application methods, you will need to configure those in the `./storybook/preview.js` file. | ||
|
||
Therefore, Storybook provides you with a `setup` function exported from this package, which receives as a callback your Storybook instance, which you can interact with and add your custom configuration. | ||
|
||
```js | ||
// .storybook/preview.js | ||
|
||
import { setup } from '@storybook/vue3'; | ||
|
||
setup((app) => { | ||
app.use(MyPlugin); | ||
app.component('my-component', MyComponent); | ||
app.mixin({ | ||
/* My mixin */ | ||
}); | ||
}); | ||
``` | ||
See [documentation](https://storybook.js.org/docs/8.0/get-started/vue3-webpack5?renderer=vue) for installation instructions, usage examples, APIs, and more. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
--- | ||
title: Storybook for Vue & Webpack | ||
--- | ||
|
||
export const SUPPORTED_RENDERER = 'vue'; | ||
|
||
Storybook for Vue & Webpack is a [framework](../contribute/framework.md) that makes it easy to develop and test UI components in isolation for [Vue](https://vuejs.org/) applications built with [Webpack](https://webpack.js.org/). | ||
|
||
<If notRenderer={SUPPORTED_RENDERER}> | ||
|
||
<Callout variant="info"> | ||
|
||
Storybook for Vue & Webpack is only supported in [Vue](?renderer=vue) projects. | ||
|
||
</Callout> | ||
|
||
<!-- End non-supported renderers --> | ||
|
||
</If> | ||
|
||
<If renderer={SUPPORTED_RENDERER}> | ||
|
||
## Requirements | ||
|
||
- Vue ≥ 3.0 | ||
- Webpack ≥ 5.0 | ||
- Storybook ≥ 8.0 | ||
|
||
## Getting started | ||
|
||
### In a project without Storybook | ||
|
||
Follow the prompts after running this command in your Vue project's root directory: | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
<CodeSnippets | ||
paths={[ | ||
'common/init-command.npx.js.mdx', | ||
'common/init-command.yarn.js.mdx', | ||
'common/init-command.pnpm.js.mdx', | ||
]} | ||
/> | ||
|
||
<!-- prettier-ignore-end --> | ||
|
||
[More on getting started with Storybook.](./install.md) | ||
|
||
### In a project with Storybook | ||
|
||
This framework is designed to work with Storybook 7+. If you’re not already using v7, upgrade with this command: | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
<CodeSnippets | ||
paths={[ | ||
'common/storybook-upgrade.npm.js.mdx', | ||
'common/storybook-upgrade.pnpm.js.mdx', | ||
'common/storybook-upgrade.yarn.js.mdx' | ||
]} | ||
/> | ||
|
||
<!-- prettier-ignore-end --> | ||
|
||
#### Automatic migration | ||
|
||
When running the `upgrade` command above, you should get a prompt asking you to migrate to `@storybook/vue3-webpack5`, which should handle everything for you. In case that auto-migration does not work for your project, refer to the manual migration below. | ||
|
||
#### Manual migration | ||
|
||
First, install the framework: | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
<CodeSnippets | ||
paths={[ | ||
'vue/vue-webpack5-install.npm.js.mdx', | ||
'vue/vue-webpack5-install.pnpm.js.mdx', | ||
'vue/vue-webpack5-install.yarn.js.mdx' | ||
]} | ||
/> | ||
|
||
<!-- prettier-ignore-end --> | ||
|
||
Next, install and register your appropriate compiler addon, depending on whether you're using SWC (recommended) or Babel: | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
<CodeSnippets | ||
paths={[ | ||
'common/storybook-addon-compiler-swc-auto-install.npm.js.mdx', | ||
'common/storybook-addon-compiler-swc-auto-install.pnpm.js.mdx', | ||
'common/storybook-addon-compiler-swc-auto-install.yarn.js.mdx', | ||
]} | ||
/> | ||
|
||
<!-- prettier-ignore-end --> | ||
|
||
or | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
<CodeSnippets | ||
paths={[ | ||
'common/storybook-addon-compiler-babel-auto-install.npm.js.mdx', | ||
'common/storybook-addon-compiler-babel-auto-install.pnpm.js.mdx', | ||
'common/storybook-addon-compiler-babel-auto-install.yarn.js.mdx', | ||
]} | ||
/> | ||
|
||
<!-- prettier-ignore-end --> | ||
|
||
More details can be found in the [Webpack builder docs](../builders/webpack.md#compiler-support). | ||
|
||
Finally, update your `.storybook/main.js|ts` to change the framework property: | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
<CodeSnippets | ||
paths={[ | ||
'vue/vue-webpack5-add-framework.js.mdx', | ||
'vue/vue-webpack5-add-framework.ts.mdx' | ||
]} | ||
/> | ||
|
||
<!-- prettier-ignore-end --> | ||
|
||
## Extending the Vue application | ||
|
||
Storybook creates a [Vue 3 application](https://vuejs.org/api/application.html#application-api) for your component preview. | ||
When using global custom components (`app.component`), directives (`app.directive`), extensions (`app.use`), or other application methods, you will need to configure those in the `./storybook/preview.js` file. | ||
|
||
Therefore, Storybook provides you with a `setup` function exported from this package, which receives as a callback your Storybook instance, which you can interact with and add your custom configuration. | ||
|
||
```js | ||
// .storybook/preview.js | ||
|
||
import { setup } from '@storybook/vue3'; | ||
|
||
setup((app) => { | ||
app.use(MyPlugin); | ||
app.component('my-component', MyComponent); | ||
app.mixin({ | ||
/* My mixin */ | ||
}); | ||
}); | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
### Storybook doesn't work with my Vue 2 project | ||
|
||
[Vue 2 entered End of Life](https://v2.vuejs.org/lts/) (EOL) on December 31st, 2023, and is no longer maintained by the Vue team. As a result, Storybook no longer supports Vue 2. We recommend you upgrade your project to Vue 3, which Storybook fully supports. If that's not an option, you can still use Storybook with Vue 2 by installing the latest version of Storybook 7 with the following command: | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
<CodeSnippets | ||
paths={[ | ||
'common/storybook-init-v7.npx.js.mdx', | ||
'common/storybook-init-v7.yarn.js.mdx', | ||
'common/storybook-init-v7.pnpm.js.mdx', | ||
]} | ||
/> | ||
|
||
<!-- prettier-ignore-end --> | ||
|
||
## API | ||
|
||
### Options | ||
|
||
You can pass an options object for additional configuration if needed: | ||
|
||
```ts | ||
// .storybook/main.ts | ||
import type { StorybookConfig } from '@storybook/vue-webpack5'; | ||
|
||
const config: StorybookConfig = { | ||
framework: { | ||
name: '@storybook/vue-webpack5', | ||
options: { | ||
// ... | ||
}, | ||
}, | ||
}; | ||
|
||
export default config; | ||
``` | ||
|
||
#### `builder` | ||
|
||
Type: `Record<string, any>` | ||
|
||
Configure options for the [framework's builder](../api/main-config-framework.md#optionsbuilder). For this framework, available options can be found in the [Webpack builder docs](../builders/webpack.md). | ||
|
||
<!-- End supported renderers --> | ||
|
||
</If> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```js | ||
// .storybook/main.js | ||
export default { | ||
// ... | ||
framework: '@storybook/vue3-webpack5', // 👈 Add this | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
```ts | ||
// .storybook/main.ts | ||
import { StorybookConfig } from '@storybook/vue3-webpack5'; | ||
|
||
const config: StorybookConfig = { | ||
// ... | ||
framework: '@storybook/vue3-webpack5', // 👈 Add this | ||
}; | ||
|
||
export default config; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```shell | ||
npm install --save-dev @storybook/vue3-webpack5 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```shell | ||
pnpm install --save-dev @storybook/vue3-webpack5 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```shell | ||
yarn add --dev @storybook/vue3-webpack5 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters