This file contains hidden or 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') | |
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin'); | |
const BUNDLE_LOADER_RULES = [ | |
{ | |
test: /.*\/admin\/.*\.widget\.jsx$/, | |
use: [ | |
{ | |
loader: 'bundle-loader', | |
options: { |
This file contains hidden or 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 getLazyComponent from './getLazyComponent' | |
function renderWidget(domSelector, widgetName, props) { | |
ReactDOM.render( | |
React.createElement(getLazyComponent(widgetName, props)), | |
document.querySelector(domSelector) | |
) | |
} |
This file contains hidden or 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 widgetMap from './widgetMap' | |
function getLazyComponent(widgetName, defaultProps, loader = 'loading...') { | |
if (!widgetMap[widgetName]) | |
throw 'WidgetNotFound: Provided widget name does not exist.' | |
return ( | |
class LoaderWrapper extends React.Component { | |
static defaultProps = defaultProps |
This file contains hidden or 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 widgetMap = {} | |
const requireContext = require.context('../src', true, /\.widget.jsx$/) | |
const modulesPathList = requireContext.keys() | |
const widgetNameRegex = /[a-z-A-Z]+(?=\.widget\.jsx$)/ | |
for (const path of modulesPathList) { | |
widgetMap[widgetNameRegex.exec(path)[0]] = requireContext(path) | |
} | |
export default widgetMap |
This file contains hidden or 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
<html> | |
<head> | |
<title>WDD</title> | |
</head> | |
<body> | |
<div id="content"></div> | |
<script src="./build/vendor.bundle.js"></script> | |
<script src="./build/index.bundle.js"></script> | |
<script> | |
window.renderWidget('#content', 'user') |
NewerOlder