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

feat: improve TypeScript definition #99

Merged
merged 1 commit into from
Sep 23, 2024
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export default defineConfig({
react: {
requiredVersion: '18',
},
'react-dom': {
requiredVersion: '18',
},
'react-dom/': {
requiredVersion: '18',
},
},
}),
// If you set build.target: "chrome89", you can remove this plugin
Expand Down
15 changes: 8 additions & 7 deletions src/utils/normalizeModuleFederationOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface ExposesItem {
export interface NormalizedShared {
[key: string]: ShareItem;
}
export interface RemoteObjectConfig { type?: string; name?: string; entry?: string; entryGlobalName?: string; shareScope?: string }

function normalizeExposesItem(key: string, item: string | { import: string }): ExposesItem {
let importPath: string = '';
Expand Down Expand Up @@ -59,17 +60,17 @@ export function normalizeRemotes(
| Record<
string,
| string
| { type: string; name: string; entry: string; entryGlobalName: string; shareScope: string }
| RemoteObjectConfig
>
| undefined
): Record<
string,
{ type: string; name: string; entry: string; entryGlobalName: string; shareScope: string }
RemoteObjectConfig
> {
if (!remotes) return {};
const result: Record<
string,
{ type: string; name: string; entry: string; entryGlobalName: string; shareScope: string }
RemoteObjectConfig
> = {};
if (typeof remotes === 'object') {
Object.keys(remotes).forEach((key) => {
Expand All @@ -83,8 +84,8 @@ function normalizeRemoteItem(
key: string,
remote:
| string
| { type: string; name: string; entry: string; entryGlobalName: string; shareScope: string }
): { type: string; name: string; entry: string; entryGlobalName: string; shareScope: string } {
| RemoteObjectConfig
): RemoteObjectConfig {
if (typeof remote === 'string') {
const [entryGlobalName] = remote.split('@');
const entry = remote.replace(entryGlobalName + '@', '');
Expand Down Expand Up @@ -235,7 +236,7 @@ export type ModuleFederationOptions = {
| Record<
string,
| string
| { type: string; name: string; entry: string; entryGlobalName: string; shareScope: string }
| RemoteObjectConfig
>
| undefined;
runtime?: any;
Expand Down Expand Up @@ -271,7 +272,7 @@ export interface NormalizedModuleFederationOptions {
// remoteType: string;
remotes: Record<
string,
{ type: string; name: string; entry: string; entryGlobalName: string; shareScope: string }
RemoteObjectConfig
>;
runtime: any;
shareScope: string;
Expand Down