Skip to content

Commit

Permalink
chore: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
2heal1 committed Feb 19, 2025
1 parent 3e3a36f commit 7347710
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
1 change: 1 addition & 0 deletions apps/modernjs-ssr/remote/module-federation.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 0 additions & 3 deletions packages/modernjs/src/cli/configPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
43 changes: 22 additions & 21 deletions packages/modernjs/src/cli/ssrPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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(() => {
Expand Down Expand Up @@ -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',
});
}
},
},
};
});
Expand Down
34 changes: 1 addition & 33 deletions packages/modernjs/src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
};

0 comments on commit 7347710

Please sign in to comment.