Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Support custom PREVIEW URL for block story iframe #16773

Merged
merged 18 commits into from
Dec 9, 2021
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dist
.tern-port
*.DS_Store
.cache
.parcel-cache
coverage/
*.lerna_backup
build
Expand Down Expand Up @@ -41,4 +42,4 @@ examples/angular-cli/addon-jest.testresults.json
!/**/.yarn/plugins
!/**/.yarn/sdks
!/**/.yarn/versions
/**/.pnp.*
/**/.pnp.*
2 changes: 1 addition & 1 deletion addons/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"prop-types": "^15.7.2",
"react-inspector": "^5.1.0",
"regenerator-runtime": "^0.13.7",
"telejson": "^5.3.2",
"telejson": "^5.3.3",
"ts-dedent": "^2.0.0",
"util-deprecate": "^1.0.2",
"uuid-browser": "^3.1.0"
Expand Down
2 changes: 1 addition & 1 deletion app/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"regenerator-runtime": "^0.13.7",
"sass-loader": "^10.1.0",
"strip-json-comments": "3.1.1",
"telejson": "^5.3.2",
"telejson": "^5.3.3",
"ts-dedent": "^2.0.0",
"ts-loader": "^8.0.14",
"tsconfig-paths-webpack-plugin": "^3.3.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/angular-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"core-js": "^3.8.2",
"rxjs": "^6.6.3",
"sass": "^1.43.4",
"telejson": "^5.3.2",
"telejson": "^5.3.3",
"zone.js": "^0.11.3"
},
"devDependencies": {
Expand Down
7 changes: 3 additions & 4 deletions examples/standalone-preview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ This project demonstrates a preview running in standalone mode using `parcel`.
To run the standalone preview:

```
yarn storybook
yarn storybook-preview
```

This starts a `parcel` dev server on port `1337`.

To view the stories in the storybook UI:

```
cd ../official-storybook
npm storybook -- --preview-url=http://localhost:1337/iframe.html # or yarn
yarn storybook
```

This runs the Storybook dev server, but instead of showing `official-storybook`'s stories, it attaches to the `parcel` dev server, lists its stories in the navigation, and shows its stories in the preview iframe.
This runs the Storybook dev server (Found in ../official-storybook), but instead of showing `official-storybook`'s stories, it attaches to the `parcel` dev server, lists its stories in the navigation, and shows its stories in the preview iframe.

> NOTE: This can be run from any working storybook, not just `official-storybook`!
3 changes: 3 additions & 0 deletions examples/standalone-preview/addPreview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export {};

global.PREVIEW_URL = process.env.PREVIEW_URL;
7 changes: 5 additions & 2 deletions examples/standalone-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
"version": "6.5.0-alpha.2",
"private": true,
"scripts": {
"storybook": "parcel ./storybook.html --port 1337"
"storybook-preview": "cross-env PREVIEW_URL=external-iframe.html parcel ./storybook.html --port 1337",
"storybook": "cross-env STORYBOOK_DISPLAY_WARNING=true DISPLAY_WARNING=true start-storybook -p 9011 -c ../official-storybook --no-manager-cache --preview-url=http://localhost:1337/external-iframe.html"
},
"devDependencies": {
"@storybook/addon-docs": "6.5.0-alpha.2",
"@storybook/cli": "6.5.0-alpha.2",
"@storybook/react": "6.5.0-alpha.2",
"parcel": "^1.12.4",
"cross-env": "^7.0.3",
"parcel": "2.0.1",
"react": "16.14.0",
"react-dom": "16.14.0"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/standalone-preview/storybook.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body>
<div id="root"></div>
<div id="docs-root"></div>
<script src="./storybook.ts"></script>
<script type="module" src="./storybook.ts"></script>
<div class="sb-errordisplay sb-wrapper">
<div id="error-message" class="sb-heading"></div>
<pre class="sb-errordisplay_code"><code id="error-stack"></code></pre>
Expand Down
1 change: 1 addition & 0 deletions examples/standalone-preview/storybook.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './addPreview';
import { configure, addParameters } from '@storybook/react';
import { DocsPage, DocsContainer } from '@storybook/addon-docs';

Expand Down
2 changes: 1 addition & 1 deletion lib/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"memoizerific": "^1.11.3",
"regenerator-runtime": "^0.13.7",
"store2": "^2.12.0",
"telejson": "^5.3.2",
"telejson": "^5.3.3",
"ts-dedent": "^2.0.0",
"util-deprecate": "^1.0.2"
},
Expand Down
2 changes: 2 additions & 0 deletions lib/builder-webpack4/src/preview/iframe-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default async (options: Options & Record<string, any>): Promise<Configura
framework,
frameworkPath,
presets,
previewUrl,
typescriptOptions,
modern,
features,
Expand Down Expand Up @@ -188,6 +189,7 @@ export default async (options: Options & Record<string, any>): Promise<Configura
FRAMEWORK_OPTIONS: frameworkOptions,
CHANNEL_OPTIONS: coreOptions?.channelOptions,
FEATURES: features,
PREVIEW_URL: previewUrl,
STORIES: stories.map((specifier) => ({
...specifier,
importPathMatcher: specifier.importPathMatcher.source,
Expand Down
2 changes: 2 additions & 0 deletions lib/builder-webpack5/src/preview/iframe-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default async (options: Options & Record<string, any>): Promise<Configura
framework,
frameworkPath,
presets,
previewUrl,
typescriptOptions,
modern,
features,
Expand Down Expand Up @@ -192,6 +193,7 @@ export default async (options: Options & Record<string, any>): Promise<Configura
FRAMEWORK_OPTIONS: frameworkOptions,
CHANNEL_OPTIONS: coreOptions?.channelOptions,
FEATURES: features,
PREVIEW_URL: previewUrl,
STORIES: stories.map((specifier) => ({
...specifier,
importPathMatcher: specifier.importPathMatcher.source,
Expand Down
2 changes: 1 addition & 1 deletion lib/channel-postmessage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"core-js": "^3.8.2",
"global": "^4.4.0",
"qs": "^6.10.0",
"telejson": "^5.3.2"
"telejson": "^5.3.3"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion lib/channel-websocket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@storybook/client-logger": "6.5.0-alpha.2",
"core-js": "^3.8.2",
"global": "^4.4.0",
"telejson": "^5.3.2"
"telejson": "^5.3.3"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 3 additions & 1 deletion lib/components/src/blocks/Story.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import global from 'global';
import React, { createElement, ElementType, FunctionComponent, Fragment } from 'react';

import type { Parameters } from '@storybook/api';
Expand All @@ -7,7 +8,8 @@ import { EmptyBlock } from './EmptyBlock';
import { ZoomContext } from './ZoomContext';
import { Loader } from '..';

const BASE_URL = 'iframe.html';
const { PREVIEW_URL } = global;
const BASE_URL = PREVIEW_URL || 'iframe.html';

export enum StoryError {
NO_STORY = 'No component or story to display',
Expand Down
2 changes: 1 addition & 1 deletion lib/core-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"pretty-hrtime": "^1.0.3",
"resolve-from": "^5.0.0",
"slash": "^3.0.0",
"telejson": "^5.3.2",
"telejson": "^5.3.3",
"ts-dedent": "^2.0.0",
"util-deprecate": "^1.0.2",
"webpack": "4"
Expand Down
2 changes: 1 addition & 1 deletion lib/manager-webpack4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"regenerator-runtime": "^0.13.7",
"resolve-from": "^5.0.0",
"style-loader": "^1.3.0",
"telejson": "^5.3.2",
"telejson": "^5.3.3",
"terser-webpack-plugin": "^4.2.3",
"ts-dedent": "^2.0.0",
"url-loader": "^4.1.1",
Expand Down
2 changes: 1 addition & 1 deletion lib/manager-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"regenerator-runtime": "^0.13.7",
"resolve-from": "^5.0.0",
"style-loader": "^2.0.0",
"telejson": "^5.3.2",
"telejson": "^5.3.3",
"terser-webpack-plugin": "^5.0.3",
"ts-dedent": "^2.0.0",
"util-deprecate": "^1.0.2",
Expand Down
Loading