Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/frameworks/nextjs-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"./src/null-renderer.ts",
"./src/preset.ts",
"./src/mock.ts",
"./src/next-config.ts",
"./src/next-config.cts",
"./src/pages/index.ts",
"./src/reexports/channels.ts",
"./src/reexports/core-events.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,52 @@ function addRewrites(
};
}

export const withStorybook = ({
interface WithStorybookOptions {
/**
* Port that the Next.js app will run on.
* @default 3000
*/
port: string | number;

/**
* Internal port that Storybook will run on.
* @default 34567
*/
sbPort: string | number;

/**
* URL path to Storybook's "manager" UI.
* @default 'storybook'
*/
managerPath: string;

/**
* URL path to Storybook's story preview iframe.
* @default 'storybook-preview'
*/
previewPath: string;

/**
* Directory where Storybook's config files are located.
* @default '.storybook'
*/
configDir: string;

/**
* Whether to use the NextJS app directory.
* @default undefined
*/
appDir: boolean;
}

const withStorybook = ({
port = process.env.PORT ?? 3000,
sbPort = 34567,
managerPath = 'storybook',
previewPath = 'storybook-preview',
configDir = '.storybook',
appDir = undefined,
} = {}) => {
}: Partial<WithStorybookOptions> = {}) => {
const isAppDir = appDir ?? existsSync('app');
const storybookNextJSOptions: StorybookNextJSOptions = {
appDir: isAppDir,
Expand Down Expand Up @@ -132,3 +170,5 @@ export const withStorybook = ({
]),
});
};

module.exports = withStorybook;
5 changes: 2 additions & 3 deletions code/lib/cli/src/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,8 @@ async function doInitiate(
logger.log(chalk.yellow('NOTE: installation is not 100% automated.\n'));
logger.log(`To set up Storybook, replace contents of ${chalk.cyan('next-config.js')} with:\n`);
codeLog([
"const { withStorybook } = require('@storybook/nextjs-server/next-config');",
'const nextConfig = withStorybook()({ /* your custom config here */ });',
'module.exports = nextConfig;',
"const withStorybook = require('@storybook/nextjs-server/next-config')(/* storybook config */);",
'module.exports = withStorybook({ /* nextjs config */ });',
]);
logger.log('\n Then to run your NextJS app:\n');
codeLog([packageManager.getRunCommand('dev')]);
Expand Down