-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
231 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,19 @@ export default defineConfig({ | |
router: true, | ||
}, | ||
server: { | ||
// baseUrl: '/kkkk', | ||
ssr: { | ||
mode: 'stream', | ||
}, | ||
ssrByRouteIds: ['entry-one_nested-routes/pathname/layout', 'remote@layout'], | ||
port: 3062, | ||
}, | ||
source: { | ||
alias: { | ||
// FIXME: becasue modernjs set alias value as package, so the value will use @module-federation/modern-js's @modern-js/runtime , and it will cause multiple instance | ||
'@meta/runtime': | ||
'/Users/bytedance/outter/universe/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@modern-js/runtime/dist/esm/index.js', | ||
}, | ||
}, | ||
plugins: [ | ||
appTools({ | ||
bundler: 'experimental-rspack', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
packages/modernjs/src/cli/mfRuntimePlugins/inject-node-fetch.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime'; | ||
import nodeFetch from 'node-fetch'; | ||
|
||
const injectNodeFetchPlugin: () => FederationRuntimePlugin = () => ({ | ||
name: 'node-fetch-plugin', | ||
beforeInit(args) { | ||
if (!globalThis.fetch) { | ||
// @ts-expect-error inject node-fetch | ||
globalThis.fetch = nodeFetch; | ||
} | ||
return args; | ||
}, | ||
}); | ||
export default injectNodeFetchPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime'; | ||
import nodeFetch from 'node-fetch'; | ||
import nodeRuntimePlugin from '@module-federation/node/runtimePlugin'; | ||
|
||
const injectNodeFetchPlugin: () => FederationRuntimePlugin = () => ({ | ||
name: 'inject-node-fetch-plugin', | ||
beforeInit(args) { | ||
if (!globalThis.fetch) { | ||
// @ts-expect-error inject node-fetch | ||
globalThis.fetch = nodeFetch; | ||
} | ||
return args; | ||
}, | ||
// TODO: Support pass params in runtimePlugins , supports pass different params via env. | ||
const isContainer = | ||
typeof __filename === 'string' | ||
? __filename.includes('remote') | ||
? true | ||
: false | ||
: false; | ||
const pluginName = `node-plugin-${isContainer}`; | ||
|
||
const nodePlugin: () => FederationRuntimePlugin = () => ({ | ||
name: pluginName, | ||
beforeInit: nodeRuntimePlugin().beforeInit, | ||
}); | ||
export default injectNodeFetchPlugin; | ||
|
||
export default nodePlugin; |
22 changes: 0 additions & 22 deletions
22
packages/modernjs/src/cli/mfRuntimePlugins/shared-strategy.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
declare module '@meta/runtime' { | ||
export * from '@modern-js/runtime'; | ||
} | ||
declare module '@meta/runtime/router' { | ||
export * from '@modern-js/runtime/router'; | ||
} |
60 changes: 60 additions & 0 deletions
60
packages/modernjs/src/runtime/dataLoader/plugin-inject-assets.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useContext } from 'react'; | ||
import type { Plugin } from '@modern-js/runtime'; | ||
import { getInstance } from '@module-federation/enhanced/runtime'; | ||
import { collectSSRAssets } from '../createRemoteSSRComponent'; | ||
import { RuntimeReactContext } from '@meta/runtime'; | ||
import { decodeId, getRemoteId } from './utils'; | ||
|
||
export const ssrDataLoaderInjectAssetsPlugin = (): Plugin => { | ||
return { | ||
name: '@modern-js/plugin-mf-data-loader-inject-assets', | ||
pre: ['@modern-js/plugin-router', '@modern-js/plugin-mf-data-loader'], | ||
setup: () => { | ||
return { | ||
wrapRoot(App) { | ||
const AppWrapper = (props: any) => { | ||
const instance = getInstance(); | ||
if (!instance || !instance.options.remotes.length) { | ||
return ( | ||
<> | ||
<App {...props} /> | ||
</> | ||
); | ||
} | ||
const context = useContext(RuntimeReactContext); | ||
const { remotes } = instance.options; | ||
|
||
const remoteNames = | ||
context.routerContext?.matches.map((match) => | ||
decodeId(match.route.id), | ||
) || []; | ||
const remoteIds = remoteNames.reduce((sum, cur) => { | ||
const matchRemote = remotes.find((r) => r.name === cur); | ||
if (matchRemote) { | ||
sum.add(getRemoteId(cur)); | ||
} | ||
return sum; | ||
}, new Set() as Set<string>); | ||
|
||
const assets: React.ReactNode[] = []; | ||
remoteIds.forEach((remoteId) => { | ||
assets.push( | ||
...collectSSRAssets({ | ||
id: remoteId, | ||
}), | ||
); | ||
}); | ||
|
||
return ( | ||
<> | ||
{assets} | ||
<App {...props} /> | ||
</> | ||
); | ||
}; | ||
return AppWrapper; | ||
}, | ||
}; | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.