From 8a77cf7deca45fadff069569106c5c09d659d405 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Tue, 25 May 2021 20:32:53 +0800 Subject: [PATCH] Core: Add option to build iframe even when preview URL is specified --- lib/core-common/src/types.ts | 1 + lib/core-server/src/build-dev.ts | 2 +- lib/core-server/src/build-static.ts | 3 ++- lib/core-server/src/cli/dev.ts | 1 + lib/core-server/src/cli/prod.ts | 2 ++ 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/core-common/src/types.ts b/lib/core-common/src/types.ts index f03bee04666..2d46d21775e 100644 --- a/lib/core-common/src/types.ts +++ b/lib/core-common/src/types.ts @@ -123,6 +123,7 @@ export interface CLIOptions { port?: number; ignorePreview?: boolean; previewUrl?: string; + forceBuildPreview?: boolean; host?: string; staticDir?: string[]; configDir?: string; diff --git a/lib/core-server/src/build-dev.ts b/lib/core-server/src/build-dev.ts index 96cf8849889..693a2d71e38 100644 --- a/lib/core-server/src/build-dev.ts +++ b/lib/core-server/src/build-dev.ts @@ -125,7 +125,7 @@ export async function buildDev(loadOptions: LoadOptions) { ...loadOptions, configDir: loadOptions.configDir || cliOptions.configDir || './.storybook', configType: 'DEVELOPMENT', - ignorePreview: !!cliOptions.previewUrl, + ignorePreview: !!cliOptions.previewUrl && !cliOptions.forceBuildPreview, docsMode: !!cliOptions.docs, cache, }); diff --git a/lib/core-server/src/build-static.ts b/lib/core-server/src/build-static.ts index eb66928e44d..ea7ebfed14c 100644 --- a/lib/core-server/src/build-static.ts +++ b/lib/core-server/src/build-static.ts @@ -124,7 +124,8 @@ export async function buildStatic({ packageJson, ...loadOptions }: LoadOptions) packageJson, configDir: loadOptions.configDir || cliOptions.configDir || './.storybook', outputDir: loadOptions.outputDir || cliOptions.outputDir || './storybook-static', - ignorePreview: !!loadOptions.ignorePreview || !!cliOptions.previewUrl, + ignorePreview: + (!!loadOptions.ignorePreview || !!cliOptions.previewUrl) && !cliOptions.forceBuildPreview, docsMode: !!cliOptions.docs, configType: 'PRODUCTION', cache, diff --git a/lib/core-server/src/cli/dev.ts b/lib/core-server/src/cli/dev.ts index b9de742b075..14791944bf0 100644 --- a/lib/core-server/src/cli/dev.ts +++ b/lib/core-server/src/cli/dev.ts @@ -47,6 +47,7 @@ export async function getDevCli(packageJson: { '--preview-url ', 'Disables the default storybook preview and lets your use your own' ) + .option('--force-build-preview', 'Build the preview iframe even if you are using --preview-url') .option('--docs', 'Build a documentation-only site using addon-docs') .option('--modern', 'Use modern browser modules') .parse(process.argv); diff --git a/lib/core-server/src/cli/prod.ts b/lib/core-server/src/cli/prod.ts index 2796b30bdea..27d60715363 100644 --- a/lib/core-server/src/cli/prod.ts +++ b/lib/core-server/src/cli/prod.ts @@ -15,6 +15,7 @@ export interface ProdCliOptions { uiDll?: boolean; debugWebpack?: boolean; previewUrl?: string; + forceBuildPreview?: boolean; docs?: boolean; modern?: boolean; } @@ -42,6 +43,7 @@ export function getProdCli(packageJson: { '--preview-url ', 'Disables the default storybook preview and lets your use your own' ) + .option('--force-build-preview', 'Build the preview iframe even if you are using --preview-url') .option('--docs', 'Build a documentation-only site using addon-docs') .option('--modern', 'Use modern browser modules') .parse(process.argv);