Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 837de08

Browse files
leonardo-fcdannyhw
andauthoredMar 17, 2023
Fix webpack5 and @storybook/addon-storyshots compatibility error, and a typo (storybookjs#442)
* fix: compatibility with webpack5 * fix: compatibility with @storybook/addon-storyshots * docs: typo in react-native-storybook-server --help * feat: use webpack5 in the example --------- Co-authored-by: Daniel Williams <[email protected]>
1 parent 298fd70 commit 837de08

File tree

9 files changed

+346
-19
lines changed

9 files changed

+346
-19
lines changed
 

‎app/react-native-server/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@
4343
"react": "^18.2.0",
4444
"react-dom": "18.2.0",
4545
"uuid": "^3.3.2",
46-
"webpack": "^4",
4746
"ws": "^7.1.2"
4847
},
48+
"devDependencies": {
49+
"webpack": "^5.76.2"
50+
},
4951
"peerDependencies": {
50-
"babel-loader": "^7.0.0 || ^8.0.0 || ^9.0.0"
52+
"babel-loader": "^7.0.0 || ^8.0.0 || ^9.0.0",
53+
"webpack": "^4 || ^5"
5154
},
5255
"engines": {
5356
"node": ">=16.0.0"

‎app/react-native-server/src/server/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function getCli() {
2424
.option('--ssl-cert <cert>', 'Provide an SSL certificate. (Required with --https)')
2525
.option('--ssl-key <key>', 'Provide an SSL key. (Required with --https)')
2626
.option('--smoke-test', 'Exit after successful start')
27-
.option('--ci', "CI mode (skip interactive prompts, don't open browser")
27+
.option('--ci', "CI mode (skip interactive prompts, don't open browser)")
2828
.option('--quiet', 'Suppress verbose build output');
2929

3030
program.parse();

‎app/react-native-server/src/server/options.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1+
import path from 'path';
12
import packageJson from '../../package.json';
23

34
function extendOptions(options, extendServer) {
45
const { manualId, https: secured, host, port } = options;
56
const storybookOptions = { manualId, secured, host, port };
67

8+
const config = require(path.join(options.configDir, 'main'));
9+
const useWebpack5 = config.core?.builder === 'webpack5';
10+
711
return {
812
...options,
913
framework: 'react-native',
1014
extendServer,
1115
packageJson,
12-
mode: 'dev',
1316
ignorePreview: true,
1417
corePresets: [
1518
{
16-
name: '@storybook/manager-webpack4/manager-preset',
19+
name: `@storybook/manager-webpack${useWebpack5 ? 5 : 4}/manager-preset`,
1720
options: { managerEntry: require.resolve('../client/manager') },
1821
},
1922
{

‎app/react-native/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ export const storiesOf = (kind: string, _module: NodeModule) =>
2929
export const getStorybookUI = view.getStorybookUI;
3030

3131
export * from './types/types-6.0';
32+
33+
// @storybook/addon-storyshots v6 needs global.__STORYBOOK_STORY_STORE__.initializationPromise
34+
(global as any).__STORYBOOK_STORY_STORE__ = {
35+
initializationPromise: clientApi.storyStore?.initializationPromise,
36+
};

‎examples/expo-example/.storybook/Storybook.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const StorybookUIRoot = getStorybookUI({
1212
// isSplitPanelVisible: true,
1313

1414
// onDeviceUI: false,
15-
// enableWebsockets: true,
15+
enableWebsockets: true,
1616
// theme: {
1717
// storyList: {
1818
// search: {

‎examples/expo-example/.storybook_server/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ module.exports = {
55
],
66
logLevel: 'debug',
77
env: () => ({}),
8+
core: {
9+
builder: 'webpack5',
10+
},
811
addons: ['@storybook/addon-essentials'],
912
};

‎examples/expo-example/assets/icon.png

8.18 KB
Loading

‎examples/expo-example/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
1212
"prestart": "yarn get-stories",
1313
"start": "expo start",
14-
"start-server": "NODE_OPTIONS=--openssl-legacy-provider react-native-storybook-server",
14+
"start-server": "react-native-storybook-server",
1515
"storybook-watcher": "sb-rn-watcher --config-path=./.storybook",
1616
"preweb": "yarn get-stories",
1717
"web": "expo start --web"
@@ -30,7 +30,9 @@
3030
"@storybook/addon-ondevice-knobs": "^6.5.0-rc.5",
3131
"@storybook/addon-ondevice-notes": "^6.5.0-rc.5",
3232
"@storybook/addons": "^6.5.14",
33+
"@storybook/builder-webpack5": "^6.5.16",
3334
"@storybook/docs-tools": "^6.5.14",
35+
"@storybook/manager-webpack5": "^6.5.16",
3436
"@storybook/react": "^6.5.14",
3537
"@storybook/react-native": "^6.5.0-rc.5",
3638
"@storybook/react-native-server": "^6.5.0-rc.5",

‎yarn.lock

Lines changed: 323 additions & 12 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.