From 01e7b3b34163e423dec940c1d1923eb80c153499 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Tue, 17 Jan 2023 15:41:43 +0100 Subject: [PATCH 1/2] Fix HMR issue in Manager UI --- code/frameworks/react-vite/package.json | 2 +- code/lib/builder-vite/package.json | 2 +- code/lib/builder-vite/src/vite-config.ts | 2 +- code/ui/.storybook/main.ts | 33 ++++++++++++++---------- code/yarn.lock | 8 +++--- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/code/frameworks/react-vite/package.json b/code/frameworks/react-vite/package.json index 9dad100a57c3..1e78d5ecd97e 100644 --- a/code/frameworks/react-vite/package.json +++ b/code/frameworks/react-vite/package.json @@ -52,7 +52,7 @@ "@rollup/pluginutils": "^4.2.0", "@storybook/builder-vite": "7.0.0-beta.29", "@storybook/react": "7.0.0-beta.29", - "@vitejs/plugin-react": "^3.0.0", + "@vitejs/plugin-react": "^3.0.1", "ast-types": "^0.14.2", "magic-string": "^0.26.1", "react-docgen": "6.0.0-alpha.3" diff --git a/code/lib/builder-vite/package.json b/code/lib/builder-vite/package.json index 1456c587fac9..89db838fed30 100644 --- a/code/lib/builder-vite/package.json +++ b/code/lib/builder-vite/package.json @@ -67,7 +67,7 @@ "@types/node": "^16.0.0", "rollup": "^3.0.0", "typescript": "~4.9.3", - "vite": "^4.0.0" + "vite": "^4.0.4" }, "peerDependencies": { "@preact/preset-vite": "*", diff --git a/code/lib/builder-vite/src/vite-config.ts b/code/lib/builder-vite/src/vite-config.ts index c282601e59eb..316d970189a0 100644 --- a/code/lib/builder-vite/src/vite-config.ts +++ b/code/lib/builder-vite/src/vite-config.ts @@ -91,7 +91,7 @@ export async function pluginConfig(options: Options) { } }, }, - viteExternalsPlugin(globals, { useWindow: false }), + viteExternalsPlugin(globals, { useWindow: false, disableInServe: true }), ] as PluginOption[]; // TODO: framework doesn't exist, should move into framework when/if built diff --git a/code/ui/.storybook/main.ts b/code/ui/.storybook/main.ts index 52bb8b72192d..ca2f9534cf72 100644 --- a/code/ui/.storybook/main.ts +++ b/code/ui/.storybook/main.ts @@ -1,4 +1,6 @@ +import path from 'path'; import pluginTurbosnap from 'vite-plugin-turbosnap'; +import { mergeConfig } from 'vite'; import type { StorybookConfig } from '../../frameworks/react-vite'; const isBlocksOnly = process.env.STORYBOOK_BLOCKS_ONLY === 'true'; @@ -60,19 +62,24 @@ const config: StorybookConfig = { features: { interactionsDebugger: true, }, - viteFinal: (viteConfig, { configType }) => ({ - ...viteConfig, - plugins: [ - ...(viteConfig.plugins || []), - configType === 'PRODUCTION' ? pluginTurbosnap({ rootDir: viteConfig.root || '' }) : [], - ], - optimizeDeps: { ...viteConfig.optimizeDeps, force: true }, - build: { - ...viteConfig.build, - // disable sourcemaps in CI to not run out of memory - sourcemap: process.env.CI !== 'true', - }, - }), + viteFinal: (viteConfig, { configType }) => + mergeConfig(viteConfig, { + resolve: { + alias: { + ...(configType === 'DEVELOPMENT' + ? { '@storybook/components': path.resolve(__dirname, '../components/src') } + : {}), + }, + }, + plugins: [ + configType === 'PRODUCTION' ? pluginTurbosnap({ rootDir: viteConfig.root || '' }) : [], + ], + optimizeDeps: { force: true }, + build: { + // disable sourcemaps in CI to not run out of memory + sourcemap: process.env.CI !== 'true', + }, + }), }; export default config; diff --git a/code/yarn.lock b/code/yarn.lock index 21ab5d9d6a84..5c67f5636653 100644 --- a/code/yarn.lock +++ b/code/yarn.lock @@ -6082,7 +6082,7 @@ __metadata: rollup: ^3.0.0 slash: ^3.0.0 typescript: ~4.9.3 - vite: ^4.0.0 + vite: ^4.0.4 vite-plugin-externals: ^0.5.1 peerDependencies: "@preact/preset-vite": "*" @@ -7193,7 +7193,7 @@ __metadata: "@storybook/builder-vite": 7.0.0-beta.29 "@storybook/react": 7.0.0-beta.29 "@types/node": ^16.0.0 - "@vitejs/plugin-react": ^3.0.0 + "@vitejs/plugin-react": ^3.0.1 ast-types: ^0.14.2 magic-string: ^0.26.1 react-docgen: 6.0.0-alpha.3 @@ -9305,7 +9305,7 @@ __metadata: languageName: node linkType: hard -"@vitejs/plugin-react@npm:^3.0.0": +"@vitejs/plugin-react@npm:^3.0.1": version: 3.0.1 resolution: "@vitejs/plugin-react@npm:3.0.1" dependencies: @@ -29416,7 +29416,7 @@ __metadata: languageName: node linkType: hard -"vite@npm:^4.0.0": +"vite@npm:^4.0.0, vite@npm:^4.0.4": version: 4.0.4 resolution: "vite@npm:4.0.4" dependencies: From d0c566578a1513eac1623b15428b2aa9badaab15 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Tue, 17 Jan 2023 16:40:06 +0100 Subject: [PATCH 2/2] Add missing dependencies to builder-vite package.json --- code/lib/builder-vite/package.json | 2 ++ code/yarn.lock | 2 ++ 2 files changed, 4 insertions(+) diff --git a/code/lib/builder-vite/package.json b/code/lib/builder-vite/package.json index 89db838fed30..e2fe7c976553 100644 --- a/code/lib/builder-vite/package.json +++ b/code/lib/builder-vite/package.json @@ -43,6 +43,8 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { + "@storybook/channel-postmessage": "7.0.0-beta.29", + "@storybook/channel-websocket": "7.0.0-beta.29", "@storybook/client-logger": "7.0.0-beta.29", "@storybook/core-common": "7.0.0-beta.29", "@storybook/csf-plugin": "7.0.0-beta.29", diff --git a/code/yarn.lock b/code/yarn.lock index 5c67f5636653..cbc78ea1d32b 100644 --- a/code/yarn.lock +++ b/code/yarn.lock @@ -6062,6 +6062,8 @@ __metadata: version: 0.0.0-use.local resolution: "@storybook/builder-vite@workspace:lib/builder-vite" dependencies: + "@storybook/channel-postmessage": 7.0.0-beta.29 + "@storybook/channel-websocket": 7.0.0-beta.29 "@storybook/client-logger": 7.0.0-beta.29 "@storybook/core-common": 7.0.0-beta.29 "@storybook/csf-plugin": 7.0.0-beta.29