Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storybook): storybook register extra addon babel plugins #5005

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fresh-baboons-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/storybook-builder': patch
---

fix(storybook): storybook register extra addon babel plugins
fix(storybook): storybook 注册了额外的 addon babel 插件
16 changes: 6 additions & 10 deletions packages/storybook/builder/src/plugin-storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {
BuilderPlugin,
SharedBuilderConfig,
ToolsBabelConfig,
mergeBuilderConfig,
} from '@modern-js/builder-shared';
import { CompileOptions } from '@storybook/mdx2-csf';
Expand Down Expand Up @@ -500,7 +501,6 @@ function addonAdapter(api: WebpackAPI | RspackAPI, options: Options) {
const replaceOrInsert = (plugin: PluginItem, plugins: PluginItem[]) => {
const pluginName = getPluginName(plugin);

const append = [];
for (let i = 0; i < plugins.length; i++) {
if (getPluginName(plugins[i]) === pluginName) {
if (getOptions(plugin)) {
Expand All @@ -509,12 +509,11 @@ function addonAdapter(api: WebpackAPI | RspackAPI, options: Options) {
);
plugins[i] = plugin;
}
} else {
append.push(plugin);
return;
}
}

plugins.push(...append);
plugins.push(plugin);
};

const currentPlugins = config.plugins || [];
Expand All @@ -528,17 +527,14 @@ function addonAdapter(api: WebpackAPI | RspackAPI, options: Options) {
replaceOrInsert(preset, currentPresets);
}

const finalConfig = {
...config,
const finalConfig: ToolsBabelConfig = {
...babelOptions,
plugins: currentPlugins,
presets: currentPresets,
};

if (typeof userConfig === 'function') {
return userConfig(finalConfig, utils);
} else if (typeof userConfig === 'object') {
return { ...finalConfig, ...userConfig };
if (userConfig) {
return applyOptionsChain(finalConfig, userConfig, utils);
} else {
return finalConfig;
}
Expand Down