Skip to content

Commit

Permalink
Merge pull request #14576 from merceyz/merceyz/resolve-builder
Browse files Browse the repository at this point in the history
Core: Resolve builders relatively to config file
  • Loading branch information
shilman authored Apr 13, 2021
2 parents ac693b3 + cf032f0 commit 7064642
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/core-server/src/utils/get-preview-builder.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 7064642

Please sign in to comment.