Skip to content

Commit

Permalink
fix: some more minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MadaraUchiha-314 committed Jun 26, 2024
1 parent aef2f98 commit cf39f12
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 41 deletions.
53 changes: 33 additions & 20 deletions packages/rollup-plugin-module-federation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,26 +808,39 @@ export default function federation(
chunkFileNames: '[name].js',
};
},
generateBundle(options, bundle) {
const mfManifest = generateManifest({
pkgJson,
federationConfig,
exposes,
initConfig,
federatedModuleInfo,
remoteEntryFileName,
federationRuntimeVersion:
rollupPluginModuleFederationPkgJson?.dependencies?.[
'@module-federation/runtime'
],
bundle,
remotesUsed,
});
this.emitFile({
type: 'asset',
fileName: 'mf-manifest.json',
source: JSON.stringify(mfManifest, null, 2),
});
generateBundle(_, bundle) {
if (federationConfig?.manifest) {
if (typeof federationConfig?.getPublicPath !== 'string') {
/**
* NOTO: In rspack, they check for either publicPath or getPublicPath
* In rollup the bundler doesn't provide any avenues for the user to provide publicPath
* So we rely on user providing getPublicPath function as part of the federation config.
*/
console.warn(
'getPublicPath is not specified. Skipping manifest generation',
);
} else {
const mfManifest = generateManifest({
pkgJson,
federationConfig,
exposes,
initConfig,
federatedModuleInfo,
remoteEntryFileName,
federationRuntimeVersion:
rollupPluginModuleFederationPkgJson?.dependencies?.[
'@module-federation/runtime'
],
bundle,
remotesUsed,
});
this.emitFile({
type: 'asset',
fileName: 'mf-manifest.json',
source: JSON.stringify(mfManifest, null, 2),
});
}
}
},
};
}
38 changes: 17 additions & 21 deletions packages/rollup-plugin-module-federation/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ import type {
import type { PackageJson } from 'type-fest';
import type {
ExposesObject,
RemotesObject,
FederatedModuleInfo,
FederatedModuleType,
SharedOrExposedModuleInfo,
ConsumedModuleFromRemote,
} from './types';
import type { OutputBundle, OutputChunk } from 'rollup';
import type { UserOptions, ShareArgs } from '@module-federation/runtime/types';
Expand Down Expand Up @@ -187,26 +185,24 @@ export function generateManifest({
},
[],
),
exposes: Object.entries(exposes).map(
([exposedModuleName, exposedModuleConfig]) => ({
id: `${instanceName}:${exposedModuleName.replace('./', '')}`,
name: exposedModuleName.replace('./', ''),
assets: {
js: getChunkMetaDataForModule(
exposedModuleName,
'exposed',
remoteEntryFileName,
federatedModuleInfo,
bundle,
),
css: {
async: [],
sync: [],
},
exposes: Object.entries(exposes).map(([exposedModuleName]) => ({
id: `${instanceName}:${exposedModuleName.replace('./', '')}`,
name: exposedModuleName.replace('./', ''),
assets: {
js: getChunkMetaDataForModule(
exposedModuleName,
'exposed',
remoteEntryFileName,
federatedModuleInfo,
bundle,
),
css: {
async: [],
sync: [],
},
path: exposedModuleName,
}),
),
},
path: exposedModuleName,
})),
remotes: initConfig.remotes.reduce<ManifestRemote[]>(
(remotes, remoteConfig) => {
return remotes.concat(
Expand Down

0 comments on commit cf39f12

Please sign in to comment.