From 7347710244a4a21b495e22db1bd1970f71cb1d6e Mon Sep 17 00:00:00 2001 From: 2heal1 Date: Wed, 19 Feb 2025 15:29:20 +0800 Subject: [PATCH] chore: fix --- .../nested-remote/module-federation.config.ts | 1 + .../remote/module-federation.config.ts | 1 + packages/modernjs/src/cli/configPlugin.ts | 3 -- packages/modernjs/src/cli/ssrPlugin.ts | 43 ++++++++++--------- packages/modernjs/src/cli/utils.ts | 34 +-------------- 5 files changed, 25 insertions(+), 57 deletions(-) diff --git a/apps/modernjs-ssr/nested-remote/module-federation.config.ts b/apps/modernjs-ssr/nested-remote/module-federation.config.ts index 4a59d0c07f6..474fd25ecd9 100644 --- a/apps/modernjs-ssr/nested-remote/module-federation.config.ts +++ b/apps/modernjs-ssr/nested-remote/module-federation.config.ts @@ -2,6 +2,7 @@ import { createModuleFederationConfig } from '@module-federation/modern-js'; export default createModuleFederationConfig({ name: 'nested_remote', filename: 'remoteEntry.js', + dts: false, exposes: { './Content': './src/components/Content.tsx', }, diff --git a/apps/modernjs-ssr/remote/module-federation.config.ts b/apps/modernjs-ssr/remote/module-federation.config.ts index 36b2e8aff16..a5e99a0d670 100644 --- a/apps/modernjs-ssr/remote/module-federation.config.ts +++ b/apps/modernjs-ssr/remote/module-federation.config.ts @@ -2,6 +2,7 @@ import { createModuleFederationConfig } from '@module-federation/modern-js'; export default createModuleFederationConfig({ name: 'remote', filename: 'remoteEntry.js', + dts: false, exposes: { './Image': './src/components/Image.tsx', './Button': './src/components/Button.tsx', diff --git a/packages/modernjs/src/cli/configPlugin.ts b/packages/modernjs/src/cli/configPlugin.ts index a7a53402292..5b5d4b747a0 100644 --- a/packages/modernjs/src/cli/configPlugin.ts +++ b/packages/modernjs/src/cli/configPlugin.ts @@ -33,9 +33,6 @@ export const moduleFederationConfigPlugin = ( userConfig.csrConfig = csrConfig; api.modifyBundlerChain((chain, { isProd, isServer }) => { - const bundlerType = - api.getAppContext().bundlerType === 'rspack' ? 'rspack' : 'webpack'; - // @ts-expect-error chain type is not correct addMyTypes2Ignored(chain, isServer ? ssrConfig : csrConfig); diff --git a/packages/modernjs/src/cli/ssrPlugin.ts b/packages/modernjs/src/cli/ssrPlugin.ts index c0ea161b7a8..6846044e2f7 100644 --- a/packages/modernjs/src/cli/ssrPlugin.ts +++ b/packages/modernjs/src/cli/ssrPlugin.ts @@ -45,7 +45,7 @@ export const moduleFederationSSRPlugin = ( }); return { entrypoint, plugins }; }); - api.modifyBundlerChain((chain, { isProd, isServer }) => { + api.modifyBundlerChain((chain, { isServer }) => { const bundlerType = api.getAppContext().bundlerType === 'rspack' ? 'rspack' : 'webpack'; @@ -64,11 +64,27 @@ export const moduleFederationSSRPlugin = ( return pluginOptions.nodePlugin; }); } - } else { - pluginOptions.distOutputDir = - pluginOptions.distOutputDir || - chain.output.get('path') || - path.resolve(process.cwd(), 'dist'); + } + // else { + // pluginOptions.distOutputDir = + // pluginOptions.distOutputDir || + // chain.output.get('path') || + // path.resolve(process.cwd(), 'dist'); + // } + + if (isServer) { + chain.target('async-node'); + if (isDev) { + chain + .plugin('UniverseEntryChunkTrackerPlugin') + .use(UniverseEntryChunkTrackerPlugin); + } + } + + if (isDev && !isServer) { + chain.externals({ + '@module-federation/node/utils': 'NOT_USED_IN_BROWSER', + }); } }); api.config(() => { @@ -105,21 +121,6 @@ export const moduleFederationSSRPlugin = ( }, ], }, - bundlerChain(chain, { isServer }) { - if (isServer) { - chain.target('async-node'); - if (isDev) { - chain - .plugin('UniverseEntryChunkTrackerPlugin') - .use(UniverseEntryChunkTrackerPlugin); - } - } - if (isDev && !isServer) { - chain.externals({ - '@module-federation/node/utils': 'NOT_USED_IN_BROWSER', - }); - } - }, }, }; }); diff --git a/packages/modernjs/src/cli/utils.ts b/packages/modernjs/src/cli/utils.ts index cd9c272efd8..fa53e89c633 100644 --- a/packages/modernjs/src/cli/utils.ts +++ b/packages/modernjs/src/cli/utils.ts @@ -7,7 +7,7 @@ import { LOCALHOST, PLUGIN_IDENTIFIER } from '../constant'; import logger from './logger'; import { autoDeleteSplitChunkCacheGroups } from '@module-federation/rsbuild-plugin/utils'; -import type { BundlerConfig, BundlerChainConfig } from '../interfaces/bundler'; +import type { BundlerChainConfig } from '../interfaces/bundler'; import type { webpack, UserConfig, @@ -377,35 +377,3 @@ export const getIPV4 = (): string => { const ipv4Interface = ipv4Interfaces[0] || { address: localIpv4 }; return ipv4Interface.address; }; - -// lib-polyfill.js: include core-js,@babel/runtime,@swc/helpers,tslib. -// lib-react.js: include react,react-dom. -// lib-router.js: include react-router,react-router-dom,history,@remix-run/router. -// lib-lodash.js: include lodash,lodash-es. -// lib-antd.js: include antd. -// lib-arco.js: include @arco-design/web-react. -// lib-semi.js: include @douyinfe/semi-ui. -// lib-axios.js: include axios. - -const SPLIT_CHUNK_MAP = { - REACT: 'react', - ROUTER: 'router', - LODASH: 'lib-lodash', - ANTD: 'lib-antd', - ARCO: 'lib-arco', - SEMI: 'lib-semi', - AXIOS: 'lib-axios', -}; -const SHARED_SPLIT_CHUNK_MAP = { - react: SPLIT_CHUNK_MAP.REACT, - 'react-dom': SPLIT_CHUNK_MAP.REACT, - 'react-router': SPLIT_CHUNK_MAP.ROUTER, - 'react-router-dom': SPLIT_CHUNK_MAP.ROUTER, - '@remix-run/router': SPLIT_CHUNK_MAP.ROUTER, - lodash: SPLIT_CHUNK_MAP.LODASH, - 'lodash-es': SPLIT_CHUNK_MAP.LODASH, - antd: SPLIT_CHUNK_MAP.ANTD, - '@arco-design/web-react': SPLIT_CHUNK_MAP.ARCO, - '@douyinfe/semi-ui': SPLIT_CHUNK_MAP.SEMI, - axios: SPLIT_CHUNK_MAP.AXIOS, -};