|
1 | 1 | import React from "react"; |
2 | 2 | import ReactDOM from "react-dom"; |
| 3 | +import Loadable from "react-loadable"; |
| 4 | +import { hot } from "react-hot-loader"; |
3 | 5 |
|
4 | | -// Utils |
5 | | -import * as serviceWorker from "utilities/serviceWorker"; |
| 6 | +// Types |
| 7 | +import { IWidget } from "typings/widgets"; |
6 | 8 |
|
7 | | -// Container |
8 | | -import App from "views/containers/App/App"; |
| 9 | +// Utilities |
| 10 | +import { isDev } from "utilities/development"; |
9 | 11 |
|
10 | | -// Styles |
11 | | -import "assets/styles/main.scss"; |
| 12 | +const widgets: IWidget[] = [ |
| 13 | + { |
| 14 | + query: "#block-adaptoffices", |
| 15 | + widget: Loadable({ |
| 16 | + loader: (): Promise<any> => import("views/widgets/Widget1/Widget1" /* webpackChunkName: "Widget1" */), |
| 17 | + loading: (): null => null, |
| 18 | + }), |
| 19 | + }, |
| 20 | + { |
| 21 | + query: "#block-contactinformation", |
| 22 | + widget: Loadable({ |
| 23 | + loader: (): Promise<any> => import("views/widgets/Widget2/Widget2" /* webpackChunkName: "Widget2" */), |
| 24 | + loading: (): null => null, |
| 25 | + }), |
| 26 | + }, |
| 27 | +]; |
12 | 28 |
|
13 | | -ReactDOM.render(<App />, document.querySelector("#root")); |
| 29 | +// Initialize the Widgets |
| 30 | +widgets.forEach( |
| 31 | + (widget): void => { |
| 32 | + const { query, widget: component } = widget; |
| 33 | + // let { } = widget; |
| 34 | + const querySelector = document.querySelector(query); |
14 | 35 |
|
15 | | -// If you want your app to work offline and load faster, you can change |
16 | | -// unregister() to register() below. Note this comes with some pitfalls. |
17 | | -// Learn more about service workers: http://bit.ly/CRA-PWA |
18 | | -serviceWorker.register(); |
| 36 | + if (!querySelector) { |
| 37 | + // eslint-disable-next-line |
| 38 | + console.warn(`The query selector doesn't exist: ${query}`); |
| 39 | + return; |
| 40 | + } |
| 41 | + |
| 42 | + // Setting up React Hot Loader |
| 43 | + const Component = isDev ? hot(module)(component) : component; |
| 44 | + |
| 45 | + // Setting ReactDOM.render for each widget. |
| 46 | + ReactDOM.render(<Component />, document.querySelector(query)); |
| 47 | + } |
| 48 | +); |
0 commit comments