Merge branch 'next' into tech/improve-version-range-webpack

This commit is contained in:
Norbert de Langen 2022-03-31 13:51:47 +02:00
commit b5edf10522
No known key found for this signature in database
GPG Key ID: FD0E78AF9A837762
4 changed files with 23 additions and 6 deletions

View File

@ -114,5 +114,5 @@ in a patch release.
#### How does my PR get merged?
- For PATCH PR's, any maintainer can review, test, approve, and merge it.
- For MINOR/MAJOR PR's, once a maintainer reviews, tests, and approves it, s/he should clear it with the other maintainers before merging it into the release branch.
- For MINOR/MAJOR PR's, once a maintainer reviews, tests, and approves it, they should clear it with the other maintainers before merging it into the release branch.
- Once a release date has been set and we cut off merging, we'll create a temporary branch to hold that release so that it doesn't block merging to `next`.

View File

@ -1,4 +1,5 @@
import fse from 'fs-extra';
import dedent from 'ts-dedent';
import { getStorybookBabelDependencies } from '@storybook/core-common';
import { NpmOptions } from '../NpmOptions';
import { SupportedLanguage, SupportedFrameworks, Builder, CoreBuilder } from '../project_types';
@ -51,6 +52,8 @@ const builderDependencies = (builder: Builder) => {
return [];
case CoreBuilder.Webpack5:
return ['@storybook/builder-webpack5', '@storybook/manager-webpack5'];
case CoreBuilder.Vite:
return ['@storybook/builder-vite'];
default:
return [builder];
}
@ -121,11 +124,15 @@ export async function baseGenerator(
const versionedPackages = await packageManager.getVersionedPackages(...packages);
const coreBuilders = [CoreBuilder.Webpack4, CoreBuilder.Webpack5, CoreBuilder.Vite] as string[];
const expandedBuilder = coreBuilders.includes(builder)
? `@storybook/builder-${builder}`
: builder;
const mainOptions =
builder !== CoreBuilder.Webpack4
? {
core: {
builder,
builder: expandedBuilder,
},
...extraMain,
}
@ -141,6 +148,16 @@ export async function baseGenerator(
copyComponents(framework, language);
}
// FIXME: temporary workaround for https://github.com/storybookjs/storybook/issues/17516
if (expandedBuilder === '@storybook/builder-vite') {
const previewHead = dedent`
<script>
window.global = window;
</script>
`;
await fse.writeFile(`.storybook/preview-head.html`, previewHead, { encoding: 'utf8' });
}
const babelDependencies = addBabel ? await getBabelDependencies(packageManager, packageJson) : [];
if (isNewFolder) {
babelDependencies.push(...getStorybookBabelDependencies());

View File

@ -81,6 +81,7 @@ export const SUPPORTED_FRAMEWORKS: SupportedFrameworks[] = [
export enum CoreBuilder {
Webpack4 = 'webpack4',
Webpack5 = 'webpack5',
Vite = 'vite',
}
// The `& {}` bit allows for auto-complete, see: https://github.com/microsoft/TypeScript/issues/29729

View File

@ -14,10 +14,9 @@ export async function getManagerBuilder(configDir: Options['configDir']) {
// - Everything else builds with `manager-webpack4`
//
// Unlike preview builders, manager building is not pluggable!
const builderPackage =
builderName === 'webpack5'
? require.resolve('@storybook/manager-webpack5', { paths: [main] })
: '@storybook/manager-webpack4';
const builderPackage = ['webpack5', '@storybook/builder-webpack5'].includes(builderName)
? require.resolve('@storybook/manager-webpack5', { paths: [main] })
: '@storybook/manager-webpack4';
const managerBuilder = await import(builderPackage);
return managerBuilder;