Skip to content

Commit

Permalink
fix: trying to get systemjs working (#61)
Browse files Browse the repository at this point in the history
* fix: trying to get systemjs working

* fix: lint

* fix: upgrading to latest

* fix: propgating libraryType

* fix: lint
  • Loading branch information
MadaraUchiha-314 authored Jul 6, 2024
1 parent a8997af commit e64413c
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 156 deletions.
335 changes: 192 additions & 143 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/examples/project-a/federation.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const getProjectBRemoteEntry = async (bundler) => {
const getProjectBRemoteEntry = async (bundler, outputFormat) => {
const remoteEntryName = bundler === 'webpack' ? 'my-remote-entry.js' : 'mf-manifest.json';
if (process.env.CI && process.env.NETLIFY) {
const projectName = 'rollup-plugin-module-federation';
const packageName = 'project-b';
const reviewId = process.env.REVIEW_ID;
const branch = process.env.BRANCH;
const prefix = branch === 'main' ? '' : `deploy-preview-${reviewId}--`;
const url = `https://${prefix}${projectName}.netlify.app/packages/examples/${packageName}/dist/${bundler}/esm/${remoteEntryName}`;
const url = `https://${prefix}${projectName}.netlify.app/packages/examples/${packageName}/dist/${bundler}/${outputFormat}/${remoteEntryName}`;
return url;
}
/**
* TODO: When we migrate to vite or something similar, we need to figure out the url from that.
*/
const domain = 'localhost:8080';
const packageName = 'project-b';
const url = `http://${domain}/packages/examples/${packageName}/dist/${bundler}/esm/${remoteEntryName}`;
const url = `http://${domain}/packages/examples/${packageName}/dist/${bundler}/${outputFormat}/${remoteEntryName}`;
return url;
};

Expand All @@ -30,7 +30,7 @@ export const federationconfig = async (bundler, outputFormat) => ({
},
remoteType: 'module',
remotes: {
'project-b': await getProjectBRemoteEntry(bundler),
'project-b': await getProjectBRemoteEntry(bundler, outputFormat),
},
shared: {
react: {
Expand Down
10 changes: 7 additions & 3 deletions packages/examples/project-a/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@
"rollup-plugin-module-federation": "*",
"webpack": "5.84.1",
"webpack-cli": "5.1.1",
"@rspack/cli": "0.7.3",
"@rspack/core": "0.7.3",
"@module-federation/enhanced": "0.2.1"
"@rspack/cli": "0.7.5",
"@rspack/core": "0.7.5",
"@module-federation/enhanced": "0.2.4"
},
"resolutions": {
"@module-federation/runtime": "0.2.4",
"@module-federation/sdk": "0.2.4"
}
}
2 changes: 1 addition & 1 deletion packages/examples/project-b/federation.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const federationconfig = (bundler, outputFormat) => ({
...(bundler === 'rollup' || bundler === 'rspack'
? {
manifest: true,
getPublicPath: `return window.location.origin + '/packages/examples/project-b/dist/${bundler}/esm/';`,
getPublicPath: `return window.location.origin + '/packages/examples/project-b/dist/${bundler}/${outputFormat}/';`,
}
: {}),
});
2 changes: 1 addition & 1 deletion packages/examples/project-b/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"react": "^18.0.0"
},
"devDependencies": {
"@module-federation/enhanced": "0.2.1",
"@module-federation/enhanced": "0.2.4",
"@originjs/vite-plugin-federation": "1.2.3",
"@rollup/plugin-commonjs": "25.0.3",
"@rollup/plugin-json": "6.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/rollup-plugin-module-federation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
]
},
"dependencies": {
"@module-federation/runtime": "0.2.1",
"@module-federation/sdk": "0.2.1",
"@module-federation/runtime": "0.2.4",
"@module-federation/sdk": "0.2.4",
"estree-walker": "3.0.3",
"magic-string": "0.30.1",
"semver": "7.5.4"
Expand Down
5 changes: 4 additions & 1 deletion packages/rollup-plugin-module-federation/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ export function generateManifest({
remoteEntry: {
name: federationConfig?.filename || `${REMOTE_ENTRY_NAME}.js`,
path: '',
type: federationConfig?.library?.type === 'module' ? 'esm' : 'global',
type:
federationConfig?.library?.type === 'module'
? 'esm'
: federationConfig?.library?.type ?? 'global',
},
types: {
path: '',
Expand Down
6 changes: 5 additions & 1 deletion packages/rollup-plugin-module-federation/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ export function getInitConfig(
entry: remoteConfig.external as string,
shareScope: remoteConfig.shareScope,
type:
remoteType === 'module' || remoteType === 'import' ? 'esm' : 'global',
remoteType === 'module' || remoteType === 'import'
? 'esm'
: remoteType === 'system'
? 'system'
: 'global',
};
}),
};
Expand Down

0 comments on commit e64413c

Please sign in to comment.