-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add withModuleFederationPlugin to simplify the generated
webpack.config.js files. This method takes a superset of a ModuleFederationConfig and adds some default values, e. g. if not stated otherwise, all npm packages and local mapped paths are shared and the filename defaults to remoteEntry.js **BREAKING CHANGE** shareAll uses the DEFAULT_SKIP_LIST by default.
- Loading branch information
1 parent
aaa7c49
commit ca26aeb
Showing
4 changed files
with
101 additions
and
8 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
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,67 @@ | ||
import { findRootTsConfigJson, shareAll } from './share-utils'; | ||
import { SharedMappings } from './shared-mappings'; | ||
|
||
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin"); | ||
|
||
export function withModuleFederationPlugin(config: unknown) { | ||
|
||
const sharedMappings = config['sharedMappings']; | ||
delete config['sharedMappings']; | ||
|
||
const mappings = new SharedMappings(); | ||
mappings.register(findRootTsConfigJson(), sharedMappings); | ||
|
||
if (!config['library']) { | ||
config['library'] = { | ||
type: 'module' | ||
} | ||
} | ||
|
||
if (!config['filename']) { | ||
config['filename'] = 'remoteEntry.js'; | ||
} | ||
|
||
if (!config['shared']) { | ||
config['shared'] = shareAll( | ||
{ singleton: true, strictVersion: true, requiredVersion: 'auto'}); | ||
} | ||
|
||
if (typeof config['shared'] === 'object') { | ||
config['shared'] = { | ||
...config['shared'], | ||
...mappings.getDescriptors() | ||
} | ||
} | ||
|
||
if (Array.isArray(config['shared'])) { | ||
config['shared'] = [ | ||
...config['shared'], | ||
mappings.getDescriptors() | ||
] | ||
} | ||
|
||
const isModule = config['library']?.['type'] === 'module'; | ||
|
||
return { | ||
output: { | ||
publicPath: "auto" | ||
}, | ||
optimization: { | ||
runtimeChunk: false | ||
}, | ||
resolve: { | ||
alias: { | ||
...mappings.getAliases(), | ||
} | ||
}, | ||
...(isModule) ? { | ||
experiments: { | ||
outputModule: true | ||
} | ||
} : {}, | ||
plugins: [ | ||
new ModuleFederationPlugin(config), | ||
mappings.getPlugin() | ||
], | ||
}; | ||
} |
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,2 +1,3 @@ | ||
export * from './utils/shared-mappings'; | ||
export * from './utils/share-utils'; | ||
export * from './utils/share-utils'; | ||
export * from './utils/with-mf-plugin'; |