Research
Security News
Malicious PyPI Package ‘pycord-self’ Targets Discord Developers with Token Theft and Backdoor Exploit
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
@storybook/builder-vite
Advanced tools
The @storybook/builder-vite package is a Storybook builder that integrates Vite as the build tool for Storybook. It allows developers to leverage Vite's fast build times and features within their Storybook environment. This package is particularly useful for projects that are already using Vite and want to maintain consistency in their build tools.
Custom Vite Configuration
Allows customization of the Vite configuration used by Storybook. Developers can add aliases, plugins, and modify other settings to tailor the build process.
module.exports = {
stories: ['../stories/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
core: {
builder: '@storybook/builder-vite'
},
async viteFinal(config, { configType }) {
// customize the Vite config here
config.resolve.alias = {
...config.resolve.alias,
'@components': '/path/to/components'
};
// return the customized config
return config;
}
};
Fast Build Times
By using Vite as the build tool, Storybook can take advantage of Vite's fast build times, leading to quicker startup and refresh times during development.
// There is no specific code sample for this feature as it is an inherent benefit of using Vite with Storybook.
Support for Vite Plugins
Enables the use of Vite plugins within the Storybook build process, allowing developers to extend functionality with Vite's rich plugin ecosystem.
module.exports = {
core: {
builder: '@storybook/builder-vite'
},
async viteFinal(config) {
config.plugins.push(myVitePlugin());
return config;
}
};
This package is a Storybook builder that uses Webpack 5 as the build tool. It is similar to @storybook/builder-vite in that it integrates a modern build tool into Storybook, but it uses Webpack instead of Vite. Webpack is more established but generally has slower build times compared to Vite.
Similar to the webpack5 builder, this package integrates Webpack 4 into Storybook. It is for projects that are still using Webpack 4 and have not yet upgraded to Webpack 5. It offers a different set of features and plugin compatibility compared to Vite.
While not a builder, this addon provides snapshot testing for Storybook stories. It complements builders like @storybook/builder-vite by adding testing capabilities to the development workflow.
Build your stories with vite for fast startup times and near-instant HMR.
This project has moved from storybook-builder-vite
to @storybook/builder-vite
as part of a larger effort to improve Vite support in Storybook. To automatically migrate your existing project, you can run
npx sb@next automigrate
To manually migrate:
storybook-builder-vite
from your package.json
dependencies@storybook/builder-vite
core.builder
setting in .storybook/main.js
to @storybook/builder-vite
.Requirements:
@storybook/builder-vite@0.1.x
)storybook-builder-vite@0.1.16
)npm install @storybook/builder-vite --save-dev
or
yarn add --dev @storybook/builder-vite
or
pnpm add --save-dev @storybook/builder-vite
Note: when using pnpm
, you may need to enable shamefully-hoist, until https://github.com/storybookjs/builder-vite/issues/55 can be fixed.
In your main.js
configuration file,
set core: { builder: "@storybook/builder-vite" }
.
For autoreload of react stories to work, they need to have a
.stories.tsx
or.stories.jsx
file suffix. See also #53
The builder supports both development mode in Storybook, and building a static production version.
See https://vitejs.dev/guide/#scaffolding-your-first-vite-project,
npm create vite@latest # follow the prompts
npx sb init --builder @storybook/builder-vite && npm run storybook
vite
and @storybook/builder-vite
webpack
, react-scripts
, and any other webpack plugins or loaders.@storybook/manager-webpack5
, you'll need to remove it, since currently the vite builder only works with manager-webpack4
, which is the default and does not need to be installed manually. Also remove @storybook/builder-webpack5
or @storybook/builder-webpack4
if they are installed.core: { builder: "@storybook/builder-vite" }
in your .storybook/main.js
file.rm -rf node_modules/.cache
)/public/index.html
file for vite (be sure there are no %PUBLIC_URL%
inside it, which is a CRA variable).jsx
or .tsx
file extension, which vite requires. This includes .storybook/preview.jsx
if it contains JSX syntax.@storybook/addon-interactions
, for now you'll need to add a workaround for jest-mock relying on the node global
variable by creating a .storybook/preview-head.html
file containing the following:<script>
window.global = window;
</script>
yarn storybook
or npm run storybook
commands you are used to.For other details about the differences between vite and webpack projects, be sure to read through the vite documentation.
The builder will not read your vite.config.js
file by default.
In .storybook/main.js
(or whatever your Storybook config file is named)
you can override the Vite config:
// use `mergeConfig` to recursively merge Vite options
const { mergeConfig } = require('vite');
module.exports = {
async viteFinal(config, { configType }) {
// return the customized config
return mergeConfig(config, {
// customize the Vite config here
resolve: {
alias: { foo: 'bar' },
},
});
},
// ... other options here
};
The viteFinal
function will give you config
which is
the builder's own Vite config. You can tweak this as you want,
for example to set up aliases, add new plugins etc.
The configType
variable will be either "DEVELOPMENT"
or "PRODUCTION"
.
The function should return the updated Vite configuration.
When using this builder with Svelte, your .storybook/main.js
(or equivalent)
can contain a svelteOptions
object to pass custom options to
vite-plugin-svelte
:
const preprocess = require('svelte-preprocess');
module.exports = {
svelteOptions: {
preprocess: preprocess({
typescript: true,
postcss: true,
sourceMap: true,
}),
},
};
Configure your .storybook/main.ts
to use TypeScript:
import type { StorybookViteConfig } from '@storybook/builder-vite';
const config: StorybookViteConfig = {
// other storybook options...,
async viteFinal(config, options) {
// modify and return config
},
};
export default config;
Or alternatively, you can use named exports:
import type { ViteFinal } from '@storybook/builder-vite';
export const viteFinal: ViteFinal = async (config, options) => {
// modify and return config
};
See Customize Vite config for details about using viteFinal
.
Docgen is used in Storybook to populate the props table in docs view, the controls panel, and for several other addons. Docgen is supported in vue and react, and there are two docgen options when using react, react-docgen
and react-docgen-typescript
. You can learn more about the pros/cons of each in this gist. By default, if we find a typescript
dependency in your package.json
file, we will assume you're using typescript and will choose react-docgen-typescript
. You can change this by setting the typescript.reactDocgen
option in your .storybook/main.js
file:
module.exports = {
typescript: {
reactDocgen: 'react-docgen`
}
}
If you're using TypeScript, we encourage you to experiment and see which option works better for your project.
The builder will by default enable Vite's server.fs.strict
option, for increased security. The default project root
is set to the parent directory of the
storybook configuration directory. This can be overridden in viteFinal.
The Vite builder cannot build itself. Are you willing to contribute? We are especially looking for vue and svelte experts, as the current maintainers are react users.
https://github.com/storybookjs/builder-vite/issues/11
Have a look at the GitHub issues for known bugs. If you find any new bugs, feel free to create an issue or send a pull request!
Please read the How to contribute guide.
The code is a monorepo with the core @storybook/builder-vite
package,
and examples (like examples/react
) to test the builder implementation.
Similar to the main storybook monorepo, you need yarn to develop this builder, because the project is organized as yarn workspaces. This lets you write new code in the core builder package, and instantly use them from the example packages.
FAQs
A plugin to run and build Storybooks with Vite
The npm package @storybook/builder-vite receives a total of 1,615,283 weekly downloads. As such, @storybook/builder-vite popularity was classified as popular.
We found that @storybook/builder-vite demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 12 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.