mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 23:32:08 +08:00
ADD option-property 'presets' so preset-properties can respond to other presets && FIX problem with cra-preset
This commit is contained in:
parent
7c5858c7f7
commit
214100aaf7
@ -6,11 +6,8 @@ import { applyCRAWebpackConfig, getReactScriptsPath, isReactScriptsInstalled } f
|
||||
type Preset = string | { name: string };
|
||||
|
||||
// Disable the built-in preset if the new preset is detected.
|
||||
const checkForNewPreset = (configDir: string) => {
|
||||
const checkForNewPreset = (presets: Preset[]) => {
|
||||
try {
|
||||
// eslint-disable-next-line global-require, import/no-dynamic-require
|
||||
const presets = require(path.resolve(configDir, 'presets.js'));
|
||||
|
||||
const hasNewPreset = presets.some((preset: Preset) => {
|
||||
const presetName = typeof preset === 'string' ? preset : preset.name;
|
||||
return presetName === '@storybook/preset-create-react-app';
|
||||
@ -27,8 +24,11 @@ const checkForNewPreset = (configDir: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export function webpackFinal(config: Configuration, { configDir }: { configDir: string }) {
|
||||
if (checkForNewPreset(configDir)) {
|
||||
export function webpackFinal(
|
||||
config: Configuration,
|
||||
{ presets, configDir }: { presets: Preset[]; configDir: string }
|
||||
) {
|
||||
if (checkForNewPreset(presets)) {
|
||||
return config;
|
||||
}
|
||||
if (!isReactScriptsInstalled()) {
|
||||
@ -40,8 +40,8 @@ export function webpackFinal(config: Configuration, { configDir }: { configDir:
|
||||
return applyCRAWebpackConfig(config, configDir);
|
||||
}
|
||||
|
||||
export function managerWebpack(config: Configuration, { configDir }: { configDir: string }) {
|
||||
if (!isReactScriptsInstalled() || checkForNewPreset(configDir)) {
|
||||
export function managerWebpack(config: Configuration, { presets }: { presets: Preset[] }) {
|
||||
if (!isReactScriptsInstalled() || checkForNewPreset(presets)) {
|
||||
return config;
|
||||
}
|
||||
|
||||
@ -53,8 +53,8 @@ export function managerWebpack(config: Configuration, { configDir }: { configDir
|
||||
};
|
||||
}
|
||||
|
||||
export function babelDefault(config: Configuration, { configDir }: { configDir: string }) {
|
||||
if (!isReactScriptsInstalled() || checkForNewPreset(configDir)) {
|
||||
export function babelDefault(config: Configuration, { presets }: { presets: Preset[] }) {
|
||||
if (!isReactScriptsInstalled() || checkForNewPreset(presets)) {
|
||||
return config;
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ function applyPresets(presets, extension, config, args) {
|
||||
const context = {
|
||||
extensionFn,
|
||||
preset,
|
||||
combinedOptions: { ...args, ...options },
|
||||
combinedOptions: { ...args, ...options, presets },
|
||||
};
|
||||
|
||||
return accumulationPromise.then(newConfig =>
|
||||
|
Loading…
x
Reference in New Issue
Block a user