From cf032f0178ffdb014cce62d350ab1b27fc4f764d Mon Sep 17 00:00:00 2001 From: merceyz Date: Tue, 13 Apr 2021 12:00:11 +0200 Subject: [PATCH] fix(core-server): resolve builder relative to config --- lib/core-server/src/utils/get-preview-builder.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/core-server/src/utils/get-preview-builder.ts b/lib/core-server/src/utils/get-preview-builder.ts index 111a5694741c..506ba16edc3d 100644 --- a/lib/core-server/src/utils/get-preview-builder.ts +++ b/lib/core-server/src/utils/get-preview-builder.ts @@ -1,16 +1,17 @@ import path from 'path'; import { getInterpretedFile, serverRequire, Options } from '@storybook/core-common'; -const DEFAULT_WEBPACK = 'webpack4'; - export async function getPreviewBuilder(configDir: Options['configDir']) { const main = path.resolve(configDir, 'main'); const mainFile = getInterpretedFile(main); const { core } = mainFile ? serverRequire(mainFile) : { core: null }; - const builder = core?.builder || DEFAULT_WEBPACK; - const builderPackage = ['webpack4', 'webpack5'].includes(builder) - ? `@storybook/builder-${builder}` - : builder; + const builder = core?.builder; + const builderPackage = builder + ? require.resolve( + ['webpack4', 'webpack5'].includes(builder) ? `@storybook/builder-${builder}` : builder, + { paths: [main] } + ) + : require.resolve('@storybook/builder-webpack4'); const previewBuilder = await import(builderPackage); return previewBuilder;