From 7dc255b7e99f2f1837c61efdad5e766e4254ee98 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Fri, 9 Jul 2021 11:11:31 +0800 Subject: [PATCH] Document webpack instance in presets --- docs/addons/writing-presets.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/addons/writing-presets.md b/docs/addons/writing-presets.md index 7a8bb72b70e4..c77ff7a926a7 100644 --- a/docs/addons/writing-presets.md +++ b/docs/addons/writing-presets.md @@ -66,6 +66,20 @@ For example, here is how Storybook automatically adopts `create-react-app`'s con - `webpackFinal` is applied to the preview config after all user presets have been applied - `managerWebpack` is applied to the manager config +As of Storybook 6.3, Storybook can run with either `webpack4` or `webpack5` builder. If your addon needs to know which version of Webpack it's running inside, the version and the actual webpack instance itself are both available inside your preset: + +```js +// .storybook/main.js + +export function webpackFinal(config, { presets }) { + const version = await presets.apply('webpackVersion'); + const instance = (await presets.apply('webpackInstance'))?.default; + + logger.info(`=> Running in webpack ${version}: ${instance}`); + return config; +} +``` + ### Manager entries The addon config `managerEntries` allows you to add addons to Storybook from within a preset. For addons that require custom webpack/babel configuration, it is easier to install the preset, and it will take care of everything.