Skip to content

Commit

Permalink
Merge pull request #23915 from storybookjs/yann/add-framework-preset-…
Browse files Browse the repository at this point in the history
…to-every-framework

Preset: Add common preset overrides mechanism
  • Loading branch information
yannbf authored Aug 23, 2023
2 parents f8bcec8 + f5a469b commit 6889787
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
8 changes: 7 additions & 1 deletion code/lib/core-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
"node": "./dist/presets/common-preset.js",
"require": "./dist/presets/common-preset.js"
},
"./dist/presets/common-override-preset": {
"types": "./dist/presets/common-override-preset.d.ts",
"node": "./dist/presets/common-override-preset.js",
"require": "./dist/presets/common-override-preset.js"
},
"./public/favicon.svg": "./public/favicon.svg",
"./package.json": "./package.json"
},
Expand Down Expand Up @@ -119,7 +124,8 @@
"entries": [
"./src/index.ts",
"./src/presets/babel-cache-preset.ts",
"./src/presets/common-preset.ts"
"./src/presets/common-preset.ts",
"./src/presets/common-override-preset.ts"
],
"platform": "node"
},
Expand Down
9 changes: 7 additions & 2 deletions code/lib/core-server/src/build-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export async function buildDevStandalone(
// We hope to remove this in SB8
let presets = await loadAllPresets({
corePresets,
overridePresets: [],
overridePresets: [
require.resolve('@storybook/core-server/dist/presets/common-override-preset'),
],
...options,
});

Expand Down Expand Up @@ -112,7 +114,10 @@ export async function buildDevStandalone(
...corePresets,
require.resolve('@storybook/core-server/dist/presets/babel-cache-preset'),
],
overridePresets: previewBuilder.overridePresets ?? [],
overridePresets: [
...(previewBuilder.overridePresets || []),
require.resolve('@storybook/core-server/dist/presets/common-override-preset'),
],
...options,
});

Expand Down
9 changes: 7 additions & 2 deletions code/lib/core-server/src/build-static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export async function buildStaticStandalone(options: BuildStaticStandaloneOption
require.resolve('@storybook/core-server/dist/presets/common-preset'),
...corePresets,
],
overridePresets: [],
overridePresets: [
require.resolve('@storybook/core-server/dist/presets/common-override-preset'),
],
...options,
});

Expand All @@ -103,7 +105,10 @@ export async function buildStaticStandalone(options: BuildStaticStandaloneOption
...corePresets,
require.resolve('@storybook/core-server/dist/presets/babel-cache-preset'),
],
overridePresets: previewBuilder.overridePresets || [],
overridePresets: [
...(previewBuilder.overridePresets || []),
require.resolve('@storybook/core-server/dist/presets/common-override-preset'),
],
...options,
});

Expand Down
14 changes: 14 additions & 0 deletions code/lib/core-server/src/presets/common-override-preset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { PresetProperty, StorybookConfig } from '@storybook/types';

export const framework: PresetProperty<'framework', StorybookConfig> = async (config) => {
// This will get called with the values from the user's main config, but before
// framework preset from framework packages e.g. react-webpack5 gets called.
// This means we can add default values to the framework config, before it's requested by other packages.
const name = typeof config === 'string' ? config : config?.name;
const options = typeof config === 'string' ? {} : config?.options || {};

return {
name,
options,
};
};

0 comments on commit 6889787

Please sign in to comment.