Skip to content

Commit

Permalink
remove the user's build property of their vite config, because it's a…
Browse files Browse the repository at this point in the history
… source of conflicts
  • Loading branch information
ndelangen committed Nov 28, 2022
1 parent 30cfe6c commit 0a86cd2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions code/lib/builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"devDependencies": {
"@types/express": "^4.17.13",
"@types/node": "^16.0.0",
"ts-dedent": "^2.0.0",
"typescript": "^4.9.3",
"vite": "^3.1.3"
},
Expand Down
19 changes: 18 additions & 1 deletion code/lib/builder-vite/src/vite-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import viteReact from '@vitejs/plugin-react';
import externalGlobals from 'rollup-plugin-external-globals';
import { isPreservingSymlinks, getFrameworkName } from '@storybook/core-common';
import { globals } from '@storybook/preview/globals';
// eslint-disable-next-line import/no-extraneous-dependencies
import dedent from 'ts-dedent';
import {
codeGeneratorPlugin,
injectExportOrderPlugin,
Expand Down Expand Up @@ -40,7 +42,22 @@ export async function commonConfig(
): Promise<ViteInlineConfig> {
const configEnv = _type === 'development' ? configEnvServe : configEnvBuild;

const { config: userConfig = {} } = (await loadConfigFromFile(configEnv)) ?? {};
// I destructure away the `build` property from the user's config object
// I do this because I can contain config that breaks storybook, such as we had in a lit project.
// If the user needs to configure the `build` they need to do so in the viteFinal function in main.js.
const { config: { build: buildProperty = undefined, ...userConfig } = {} } =
(await loadConfigFromFile(configEnv)) ?? {};

if (buildProperty) {
console.warn(
dedent`
The 'build' property in your vite config is not supported by storybook. Please use the viteFinal function in main.js to configure the build.
This is because storybook needs to configure the build for you.
Often the user's (your) app, needs 'build' config that is different from storybook.
`
);
}

const sbConfig: InlineConfig = {
configFile: false,
Expand Down

0 comments on commit 0a86cd2

Please sign in to comment.