Add support for CRA without overrides

This commit is contained in:
Brody McKee 2019-12-15 19:54:41 +02:00
parent 12f90f2473
commit 3d78c71e32
3 changed files with 13 additions and 9 deletions

View File

@ -7,14 +7,12 @@ type Preset = string | { name: string };
// Disable the built-in preset if the new preset is detected.
const checkForNewPreset = (presetsList: Preset[]) => {
try {
const hasNewPreset = presetsList.some((preset: Preset) => {
const presetName = typeof preset === 'string' ? preset : preset.name;
return presetName === '@storybook/preset-create-react-app';
});
const hasNewPreset = presetsList.some((preset: Preset) => {
const presetName = typeof preset === 'string' ? preset : preset.name;
return presetName === '@storybook/preset-create-react-app';
});
return hasNewPreset;
} catch (e) {
if (!hasNewPreset) {
logger.warn('Storybook support for Create React App is now a separate preset.');
logger.warn(
'To get started with the new preset, simply add `@storybook/preset-create-react-app` to your project.'
@ -22,6 +20,8 @@ const checkForNewPreset = (presetsList: Preset[]) => {
logger.warn('The built-in preset will be disabled in Storybook 6.0.');
return false;
}
return true;
};
export function webpackFinal(

View File

@ -3,7 +3,11 @@ import findUp from 'find-up';
import path from 'path';
import { logger } from '@storybook/node-logger';
export async function createDefaultWebpackConfig(storybookBaseConfig) {
export async function createDefaultWebpackConfig(storybookBaseConfig, options) {
if (options.presetsList.some(({ name }) => name === '@storybook/preset-create-react-app')) {
return storybookBaseConfig;
}
const postcssConfigFiles = [
'.postcssrc',
'.postcssrc.json',

View File

@ -6,7 +6,7 @@ import mergeConfigs from '../utils/merge-webpack-config';
import { createDefaultWebpackConfig } from './base-webpack.config';
async function createFinalDefaultConfig(presets, config, options) {
const defaultConfig = await createDefaultWebpackConfig(config);
const defaultConfig = await createDefaultWebpackConfig(config, options);
return presets.apply('webpackFinal', defaultConfig, options);
}