Skip to content

Commit

Permalink
Adds a Module Federation innerloop experience (#16771)
Browse files Browse the repository at this point in the history
* Module federation innerloop experience

* Change files
  • Loading branch information
kenotron authored Feb 2, 2021
1 parent fac66d8 commit 497df47
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
8 changes: 8 additions & 0 deletions change/@fluentui-react-2021-02-02-11-33-13-feat-mf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Module federation innerloop experience",
"packageName": "@fluentui/react",
"email": "kchau@microsoft.com",
"dependentChangeType": "patch",
"date": "2021-02-02T19:33:13.901Z"
}
9 changes: 8 additions & 1 deletion packages/react/just.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { preset } from '@fluentui/scripts';
import { task, webpackDevServerTask, preset } from '@fluentui/scripts';

preset();

task(
'mf',
webpackDevServerTask({
config: 'webpack.mf.config.js',
}),
);
3 changes: 2 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"start:legacy": "yarn workspace @fluentui/public-docsite-resources start",
"start-test": "just-scripts jest-watch",
"test": "just-scripts test",
"update-snapshots": "just-scripts jest -u"
"update-snapshots": "just-scripts jest -u",
"mf": "just-scripts mf"
},
"devDependencies": {
"@fluentui/eslint-plugin": "^1.0.0-beta.1",
Expand Down
57 changes: 57 additions & 0 deletions packages/react/webpack.mf.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const getResolveAlias = require('@fluentui/scripts/webpack/getResolveAlias');
const { createServeConfig } = require('@fluentui/scripts/webpack/webpack-resources');
const { webpackMerge } = require('just-scripts');

const shared = {
react: { singleton: true },
'react-dom': { singleton: true },
};

const rootComponents = fs
.readdirSync(path.join(__dirname, 'src'))
.filter(filename => filename[0].toUpperCase() === filename[0])
.map(filename => filename.replace(/\.tsx?/, ''));
const rootComponentsExposes = {};
for (const component of rootComponents) {
rootComponentsExposes[`./lib/${component}`] = `@fluentui/react/src/${component}`;
}

const myConfig = {
output: {},
entry: {},
mode: 'development',
devtool: 'cheap-module-source-map',
optimization: {
concatenateModules: false,
},
module: {
rules: [],
},
plugins: [
new webpack.container.ModuleFederationPlugin({
name: 'fluentuiReact',
filename: 'remoteEntry.js',
exposes: {
...rootComponentsExposes,
'./lib/compat/Button': '@fluentui/react/src/compat/Button',
'.': '@fluentui/react/src/index',
'./lib/index': '@fluentui/react/src/index',
},
shared,
}),
],
resolve: {
alias: getResolveAlias(),
},
devServer: {
port: 2345,
contentBase: 'dist',
},
};

const metaConfig = webpackMerge.merge(createServeConfig(), myConfig);

module.exports = metaConfig;

0 comments on commit 497df47

Please sign in to comment.