Skip to content

Commit

Permalink
Merge pull request #26330 from storybookjs/jeppe/docs-vite-import
Browse files Browse the repository at this point in the history
Docs: Use dynamic Vite imports in snippets
  • Loading branch information
JReinhold authored Mar 5, 2024
2 parents 94099bb + 9621341 commit b314219
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/snippets/common/main-config-vite-final-env.js.mdx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
```js
// .storybook/main.js|ts

import { mergeConfig } from 'vite';

export default {
stories: ['../src/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
core: {
builder: '@storybook/builder-vite',
},
async viteFinal(config, { configType }) {
const { mergeConfig } = await import('vite');

if (configType === 'DEVELOPMENT') {
// Your development configuration goes here
}
Expand Down
4 changes: 2 additions & 2 deletions docs/snippets/common/main-config-vite-final.js.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
```js
// .storybook/main.js

import { mergeConfig } from 'vite';

export default {
// Replace your-framework with the framework you are using (e.g., react-vite, vue3-vite)
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
async viteFinal(config, { configType }) {
const { mergeConfig } = await import('vite');

if (configType === 'DEVELOPMENT') {
// Your development configuration goes here
}
Expand Down
4 changes: 2 additions & 2 deletions docs/snippets/common/main-config-vite-final.ts-4-9.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
// Replace your-framework with the framework you are using (e.g., react-vite, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';

import { mergeConfig } from 'vite';

const config: StorybookConfig = {
// Replace your-framework with the framework you are using (e.g., react-vite, vue3-vite)
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
async viteFinal(config, { configType }) {
const { mergeConfig } = await import('vite');

if (configType === 'DEVELOPMENT') {
// Your development configuration goes here
}
Expand Down
3 changes: 2 additions & 1 deletion docs/snippets/common/main-config-vite-final.ts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

// Replace your-framework with the framework you are using (e.g., react-vite, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';
import { mergeConfig } from 'vite';

const config = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
async viteFinal(config, { configType }) {
const { mergeConfig } = await import('vite');

if (configType === 'DEVELOPMENT') {
// Your development configuration goes here
}
Expand Down
4 changes: 2 additions & 2 deletions docs/snippets/common/storybook-vite-builder-aliasing.js.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
```js
// .storybook/main.js|ts

import { mergeConfig } from 'vite';

export default {
stories: ['../src/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
Expand All @@ -11,6 +9,8 @@ export default {
},
async viteFinal(config) {
// Merge custom configuration into the default config
const { mergeConfig } = await import('vite');

return mergeConfig(config, {
// Add dependencies to pre-optimization
optimizeDeps: {
Expand Down

0 comments on commit b314219

Please sign in to comment.