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: skip when current project is storybook #3447

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/heavy-dragons-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/rsbuild-plugin': patch
---

fix: skip when current project is storybook
16 changes: 16 additions & 0 deletions apps/rslib-module/module-federation.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createModuleFederationConfig } from '@module-federation/rsbuild-plugin';

export default createModuleFederationConfig({
name: 'rslib_provider',
exposes: {
'.': './src/index.tsx',
},
shared: {
react: {
singleton: true,
},
'react-dom': {
singleton: true,
},
},
});
25 changes: 5 additions & 20 deletions apps/rslib-module/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
import { pluginReact } from '@rsbuild/plugin-react';
import { defineConfig } from '@rslib/core';
import moduleFederationConfig from './module-federation.config';

const shared = {
dts: {
Expand Down Expand Up @@ -36,26 +37,10 @@ export default defineConfig({
root: './dist/mf',
},
},
server: {
port: 3001,
},
},
],
plugins: [
pluginReact(),
pluginModuleFederation({
name: 'rslib_provider',
exposes: {
'.': './src/index.tsx',
},
shared: {
react: {
singleton: true,
},
'react-dom': {
singleton: true,
},
},
}),
],
server: {
port: 3001,
},
plugins: [pluginReact(), pluginModuleFederation(moduleFederationConfig)],
});
21 changes: 20 additions & 1 deletion packages/rsbuild-plugin/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
moduleFederationPlugin,
sharePlugin,
} from '@module-federation/sdk';
import type { RsbuildPlugin, Rspack } from '@rsbuild/core';
import type { RsbuildConfig, RsbuildPlugin, Rspack } from '@rsbuild/core';
import logger from '../logger';

type ModuleFederationOptions =
Expand All @@ -32,6 +32,17 @@ export {

const LIB_FORMAT = ['commonjs', 'umd', 'modern-module'];

function isStoryBook(rsbuildConfig: RsbuildConfig) {
if (
rsbuildConfig.plugins?.find(
(p) =>
p && 'name' in p && p.name === 'module-federation-storybook-plugin',
)
) {
return true;
}
}

export function isMFFormat(bundlerConfig: Rspack.Configuration) {
const library = bundlerConfig.output?.library;

Expand Down Expand Up @@ -78,6 +89,8 @@ export const pluginModuleFederation = (
bundlerConfigs.forEach((bundlerConfig) => {
if (!isMFFormat(bundlerConfig)) {
return;
} else if (isStoryBook(api.getRsbuildConfig())) {
bundlerConfig.output!.uniqueName = `${moduleFederationOptions.name}-storybook-host`;
} else {
// mf
autoDeleteSplitChunkCacheGroups(
Expand Down Expand Up @@ -156,6 +169,10 @@ export const pluginModuleFederation = (

// dev config only works on format: 'mf'
api.modifyRsbuildConfig((config) => {
// skip storybook
if (isStoryBook(config)) {
return;
}
// Change some default configs for remote modules
if (moduleFederationOptions.exposes) {
config.dev ||= {};
Expand Down Expand Up @@ -192,3 +209,5 @@ export const pluginModuleFederation = (
});
},
});

export { createModuleFederationConfig } from '@module-federation/enhanced';
Loading