Skip to content

Instantly share code, notes, and snippets.

@harshaktg
harshaktg / package.json
Created September 5, 2020 03:55
Microfrontends example package.json file
{
"name": "microfrontends-example",
"version": "1.0.0",
"description": "To demonstrate micro frontends using single SPA",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"web": "live-server ."
},
"author": "Harsha Vardhan",
@harshaktg
harshaktg / package.json
Created September 5, 2020 05:10
MFE Complete package.json
{
"name": "microfrontends-example",
"version": "1.0.0",
"description": "To demonstrate micro frontends using single SPA",
"main": "index.js",
"scripts": {
"web": "live-server .",
"react": "cd ./components/reactapp && npm start",
"vue": "cd ./components/vueapp && npm run serve -- --port 4000",
"mfe": "concurrently \"npm run web\" \"npm run react\" \"npm run vue\""
@harshaktg
harshaktg / .babelrc
Created September 5, 2020 12:15
Babel config for MFE Single SPA
{
"presets": [
["@babel/preset-env", {
"targets": {
"browsers": ["last 2 versions"]
}
}],
["@babel/preset-react"]
],
"plugins": [
@harshaktg
harshaktg / webpack.config.js
Created September 5, 2020 12:18
Webpack Config MFE Single SPA
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin')
module.exports = {
mode: 'development',
entry: {
'singleSPA.config': './singleSPA.config.js',
},
output: {
@harshaktg
harshaktg / store.js
Created September 5, 2020 12:31
Store MFE Single SPA
window.myapp = {
counter: 0,
incrementor: () => {
window.myapp.counter += 1;
window.dispatchEvent(new Event('onIncrement'));
},
decrementor: () => {
window.myapp.counter -= 1;
window.dispatchEvent(new Event('onDecrement'));
}
@harshaktg
harshaktg / App.js
Created September 5, 2020 12:53
React component Single SPA
import React, { useEffect, useState } from 'react'
const App = () => {
const [val, setVal] = useState(0);
useEffect(() => {
window.addEventListener('onIncrement', () => {
setVal(window.myapp.counter);
});
window.addEventListener('onDecrement', () => {
@harshaktg
harshaktg / index.js
Created September 5, 2020 13:00
React index MFE Single SPA
import React from 'react';
import ReactDOM from 'react-dom';
import singleSpaReact from 'single-spa-react';
import App from './App';
function domElementGetter() {
return document.getElementById("react")
}
const reactLifecycles = singleSpaReact({
@harshaktg
harshaktg / App.vue
Created September 5, 2020 13:04
Vue app MFE Single SPA
<template>
<div>
<h1>Hello from Vue</h1>
<h4>My value is {{count}}</h4>
<input type="button" v-on:click="handleIncrement" value="+"></input>
<input type="button" v-on:click="handleDecrement" value="-"></input>
</div>
</template>
<script>
@harshaktg
harshaktg / index.js
Created September 5, 2020 13:05
Vue index MFE Single SPA
import Vue from 'vue';
import singleSpaVue from 'single-spa-vue';
import App from './App.vue'
const vueLifecycles = singleSpaVue({
Vue,
appOptions: {
el: '#vue',
render: r => r(App),
}
@harshaktg
harshaktg / index.js
Created September 5, 2020 13:07
Vanilla JS MFE Single SPA
import singleSpaHtml from 'single-spa-html';
const htmlLifecycles = singleSpaHtml({
template: `<h1>Hello from VanillaJS</h1>
<h2>Counter value is <span id="counterVal"></span></h2>
<input type="button" onclick="window.myapp.incrementor()" value="+"></input>
<input type="button" onclick="window.myapp.decrementor()" value="-"></input>
`,
})
htmlLifecycles.originalMount = htmlLifecycles.mount;