Skip to content

Instantly share code, notes, and snippets.

@helton
Created June 20, 2022 03:54
Show Gist options
  • Save helton/f613e39ab6c1a23455b0d8bb96c206f1 to your computer and use it in GitHub Desktop.
Save helton/f613e39ab6c1a23455b0d8bb96c206f1 to your computer and use it in GitHub Desktop.
Module Federation with Angular without ESM modules
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const mf = require("@angular-architects/module-federation/webpack");
const path = require("path");
const share = mf.share;
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(
path.join(__dirname, 'tsconfig.json')
);
module.exports = {
output: {
uniqueName: "products",
publicPath: "auto",
scriptType: 'text/javascript'
},
optimization: {
runtimeChunk: false
},
resolve: {
alias: {
...sharedMappings.getAliases(),
}
},
experiments: {
outputModule: true
},
plugins: [
new ModuleFederationPlugin({
name: "products",
filename: "remoteEntry.js",
exposes: {
'./Entrypoint': './src/entrypoint.ts',
},
shared: share({
"@angular/core": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/common": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/router": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/common/http": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
// Uncomment for sharing lib of an Angular CLI or Nx workspace
...sharedMappings.getDescriptors()
})
}),
// Uncomment for sharing lib of an Angular CLI or Nx workspace
sharedMappings.getPlugin(),
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment