Created
August 14, 2020 13:53
-
-
Save ktroach/cf94d3057882b0f5ff351f0dc8c485ad to your computer and use it in GitHub Desktop.
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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import App from './App'; | |
import { eventsToDispatch } from 'src/utils/events'; | |
export const render = (containerId, data) => { | |
const container = document.getElementById(containerId); | |
if (!container) return; | |
ReactDOM.render(<App {...data} />, container); | |
}; | |
export const unMount = containerId => { | |
const container = document.getElementById(containerId); | |
if (!container) return; | |
ReactDOM.unmountComponentAtNode(container); | |
}; | |
export const subscribe = (eventName, eventHandler) => { | |
if (!eventsToDispatch[eventName]) { | |
console.warn(`This micro frontend does not support the ${eventName} event!`); | |
return; | |
} | |
window.addEventListener(eventName, eventHandler); | |
} | |
export const unSubscribe = (eventName, eventHandler) => { | |
if (!eventsToDispatch[eventName]) { | |
console.warn(`This micro frontend does not support the ${eventName} event!`); | |
return; | |
} | |
window.removeEventListener(eventName, eventHandler, false); | |
} | |
export const customEvents = eventsToDispatch; |
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
const path = require('path'); | |
module.exports = { | |
entry: { | |
main: ['@babel/polyfill', path.resolve('.', 'src', 'microfrontend.js')] | |
}, | |
resolve: { | |
alias: { | |
src: path.resolve('.', 'src') | |
}, | |
extensions: ['*', '.js', '.jsx'] | |
}, | |
output: { | |
path: path.resolve('.', 'dist'), | |
filename: 'mf-cart.js', | |
publicPath: '/images/', | |
library: 'mfCart', | |
libraryTarget: 'window' | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.(js|jsx)$/, | |
exclude: /node_modules/, | |
loader: 'babel-loader' | |
} | |
] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment