Skip to content

Commit aa1ba41

Browse files
committed
Added dashboard
1 parent 8c45207 commit aa1ba41

14 files changed

Lines changed: 3083 additions & 1717 deletions

File tree

.github/workflows/dashboard.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: deploy-dashboard
2+
on:
3+
push:
4+
branches:
5+
- master
6+
paths:
7+
- 'packages/dashboard/**'
8+
9+
defaults:
10+
run:
11+
working-directory: packages/dashboard
12+
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
- run : npm install
21+
- run : npm run build
22+
23+
- uses: shinyinc/action-aws-cli@v1.2
24+
- run: aws s3 sync dist s3://${{secrets.AWS_S3_BUCKET_NAME}}/dashboard/latest
25+
env:
26+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
27+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
28+
29+
- run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/dashboard/latest/remteEntry.js"
30+
env:
31+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
32+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
33+
AWS_DEFAULT_REGION: us-east-1
34+

packages/container/config/webpack.dev.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const packageJson = require('../package.json') // Import package.json to get sha
77
const devConfig = {
88
mode: 'development', // Set the mode to development
99
output:{
10-
publicPath: 'http://localhost:8080' // Set public path for development
10+
publicPath: 'http://localhost:8080/' // Set public path for development
1111
},
1212
devServer:{
1313
port:8080,
@@ -20,7 +20,8 @@ const devConfig = {
2020
name: 'container',
2121
remotes:{
2222
marketing: 'marketing@http://localhost:8081/remoteEntry.js', // Remote module from marketing
23-
auth: 'auth@http://localhost:8082/remoteEntry.js' // Remote module from auth
23+
auth: 'auth@http://localhost:8082/remoteEntry.js', // Remote module from auth
24+
dashboard: 'dashboard@http://localhost:8083/remoteEntry.js' // Remote module from dashboard
2425

2526
},
2627
shared:packageJson.dependencies // Shared dependencies

packages/container/config/webpack.prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const prodConfig = {
1717
remotes:{
1818
'marketing': `marketing@${domain}/marketing/latest/remoteEntry.js`,
1919
'auth': `auth@${domain}/auth/latest/remoteEntry.js`,
20-
// 'dashboard': `dashboard@${domain}/dashboard/remoteEntry.js`
20+
'dashboard': `dashboard@${domain}/dashboard/latest/remoteEntry.js`
2121
},
2222
shared: packageJson.dependencies,
2323
})

packages/container/src/App.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
1-
import React, {lazy, Suspense, useState} from "react";
2-
import { BrowserRouter,Route,Switch} from "react-router-dom";
1+
import React, {lazy, Suspense, useState,useEffect} from "react";
2+
import { Router,Route,Switch,Redirect} from "react-router-dom";
33
import {
44
StylesProvider,
55
createGenerateClassName,
66
} from "@material-ui/core/styles";
7+
import { createBrowserHistory } from "history";
78

89
import Progress from "./components/Progress";
910
import Header from "./components/Header";
1011

1112
const MarketingLazy = lazy(() => import("./components/MarketingApp"));
1213
const AuthLazy = lazy(() => import("./components/AuthApp"));
14+
const DashboardLazy = lazy(() => import("./components/DashboardApp"));
1315

1416

1517
const generateClassName = createGenerateClassName({
1618
productionPrefix: "co", // co for container
1719
});
1820

21+
const history = createBrowserHistory();
22+
1923
export default () => {
2024
const [isSignedIn,setIsSignedIn] = useState(false);
25+
26+
useEffect(()=>{
27+
if(isSignedIn){
28+
history.push('/dashboard');
29+
}
30+
},[isSignedIn]);
31+
2132
return (
22-
<BrowserRouter>
33+
<Router history={history}>
2334
<StylesProvider generateClassName={generateClassName}>
2435
<div>
2536
<Header onSignOut={()=>setIsSignedIn(false)} isSignedIn={isSignedIn}/>
@@ -30,11 +41,15 @@ const [isSignedIn,setIsSignedIn] = useState(false);
3041
<Route path ="/auth">
3142
<AuthLazy onSignIn={()=>setIsSignedIn(true)}/>
3243
</Route>
44+
<Route path ="/dashboard">
45+
{ !isSignedIn && <Redirect to ="/"/>}
46+
<DashboardLazy />
47+
</Route>
3348
<Route path ="/" component ={MarketingLazy}/>
3449
</Switch>
3550
</Suspense>
3651
</div>
3752
</StylesProvider>
38-
</BrowserRouter>
53+
</Router>
3954
);
4055
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { mount } from "dashboard/DashboardApp" //dashboard is remote module name and DashboardApp is the exposed module in marketing dev config
2+
import React, { useRef, useEffect } from "react";
3+
4+
export default () => {
5+
const ref = useRef(null);
6+
7+
useEffect(() => {
8+
mount(ref.current)
9+
},[]);
10+
11+
return <div ref={ref} />;
12+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const { VueLoaderPlugin } = require("vue-loader");
2+
3+
module.exports = {
4+
entry: "./src/index.js", // Entry point of the application
5+
output: {
6+
filename: "[name].[contenthash].js", // Output bundle file name
7+
},
8+
resolve: {
9+
extensions: [".js", ".vue"], // Resolve these file extensions
10+
},
11+
module: {
12+
rules: [
13+
{
14+
test: /\.(png|jpe?g|gif|woff|svg|eot|ttf)$/i, // Match image files
15+
use: [
16+
{
17+
loader: "file-loader", // Use file-loader to handle image files
18+
},
19+
],
20+
},
21+
{
22+
test: /\.vue$/, // Match Vue single-file components
23+
use: "vue-loader", // Use Vue loader to process .vue files
24+
},
25+
{
26+
test: /\.scss|\.css$/,
27+
use: ['vue-style-loader', 'style-loader', 'css-loader', 'sass-loader'],
28+
},
29+
{
30+
test: /\.js$/, // Match JavaScript files
31+
exclude: /node_modules/, // Exclude node_modules directory with babel-loader
32+
use: {
33+
loader: "babel-loader", // Use Babel loader to transpile JavaScript files
34+
options: {
35+
presets: ["@babel/preset-env"], // Use presets for modern JavaScript and React
36+
plugins: ["@babel/plugin-transform-runtime"], // Use plugin to optimize runtime code
37+
},
38+
},
39+
},
40+
],
41+
},
42+
plugins: [
43+
new VueLoaderPlugin(), //Plugin to handle Vue files
44+
],
45+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const {merge} = require('webpack-merge'); //To merge the common and development configurations
2+
const htmlWebpackPlugin = require('html-webpack-plugin');
3+
const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
4+
const commonConfig = require('./webpack.common'); // Import common configuration
5+
const packageJson = require('../package.json') // Import package.json to get shared dependencies
6+
7+
const devConfig = {
8+
mode: 'development', // Set the mode to development
9+
output:{
10+
publicPath: 'http://localhost:8083/' // Set public path for development
11+
},
12+
devServer:{
13+
port:8083,
14+
historyApiFallback: {
15+
index: '/index.html' // Fallback to index.html for SPA routing
16+
},
17+
headers:{
18+
'Access-Control-Allow-Origin':'*', // Allow cross-origin requests
19+
}
20+
},
21+
plugins:[
22+
new ModuleFederationPlugin({
23+
name: 'dashboard',
24+
filename:'remoteEntry.js',
25+
exposes:{
26+
'./DashboardApp':'./src/bootstrap'
27+
},
28+
shared:packageJson.dependencies // Shared dependencies
29+
}),
30+
new htmlWebpackPlugin({
31+
template: './public/index.html', // Template HTML file
32+
})
33+
]
34+
}
35+
36+
module.exports = merge(commonConfig, devConfig); // Merge common and development configurations
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const {merge} = require('webpack-merge');
2+
const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
3+
const commonConfig = require('./webpack.common.js');
4+
const packageJson = require('../package.json');
5+
6+
const prodConfig = {
7+
mode: 'production',
8+
output: {
9+
filename: '[name].[contenthash].js', // Use contenthash for better caching
10+
publicPath: '/dashboard/latest/' // Set public path for production
11+
},
12+
plugins: [
13+
new ModuleFederationPlugin({
14+
name: 'dashboard',
15+
filename: 'remoteEntry.js',
16+
exposes:{
17+
'./DashboardApp':'./src/bootstrap'
18+
},
19+
shared:packageJson.dependencies, // Shared dependencies
20+
}),
21+
]
22+
}
23+
24+
25+
module.exports = merge(commonConfig, prodConfig); // Merge common and production configurations

0 commit comments

Comments
 (0)