app.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import 'intersection-observer'
  21. import React from 'react'
  22. import ReactDOM from 'react-dom'
  23. import { Provider } from 'react-redux'
  24. import { ConnectedRouter } from 'connected-react-router'
  25. import history from 'utils/history'
  26. import App from 'containers/App'
  27. import { ConfigProvider } from 'antd'
  28. import zh_CN from 'antd/es/locale/zh_CN'
  29. import LanguageProvider from 'containers/LanguageProvider'
  30. import { translationMessages } from './i18n'
  31. import moment from 'moment'
  32. import 'moment/dist/locale/zh-cn'
  33. moment.locale('zh-cn')
  34. import '!file-loader?name=[name].[ext]!./favicon.ico'
  35. import 'file-loader?name=[name].[ext]!./.htaccess'
  36. import 'react-grid-layout/css/styles.css'
  37. import 'libs/react-resizable/css/styles.css'
  38. import 'bootstrap-datepicker/dist/css/bootstrap-datepicker3.standalone.min.css'
  39. import 'assets/fonts/iconfont.css'
  40. import 'assets/override/antd.css'
  41. import 'assets/override/react-grid.css'
  42. import 'assets/override/datepicker.css'
  43. import 'assets/less/style.less'
  44. import * as echarts from 'echarts/lib/echarts'
  45. import 'zrender/lib/svg/svg'
  46. import 'echarts/lib/chart/bar'
  47. import 'echarts/lib/chart/line'
  48. import 'echarts/lib/chart/scatter'
  49. import 'echarts/lib/chart/pie'
  50. import 'echarts/lib/chart/sankey'
  51. import 'echarts/lib/chart/funnel'
  52. import 'echarts/lib/chart/map'
  53. import 'echarts/lib/chart/lines'
  54. import 'echarts/lib/chart/effectScatter'
  55. import 'echarts/lib/chart/treemap'
  56. import 'echarts/lib/chart/heatmap'
  57. import 'echarts/lib/chart/boxplot'
  58. import 'echarts/lib/chart/graph'
  59. import 'echarts/lib/chart/gauge'
  60. import 'echarts/lib/chart/radar'
  61. import 'echarts/lib/chart/parallel'
  62. import 'echarts/lib/chart/pictorialBar'
  63. import 'echarts-wordcloud'
  64. import 'echarts/lib/component/legend'
  65. import 'echarts/lib/component/legendScroll'
  66. import 'echarts/lib/component/tooltip'
  67. import 'echarts/lib/component/toolbox'
  68. import 'echarts/lib/component/dataZoom'
  69. import 'echarts/lib/component/visualMap'
  70. import 'echarts/lib/component/geo'
  71. import 'echarts/lib/component/brush'
  72. import 'echarts/lib/component/markLine'
  73. import 'echarts/lib/component/markArea'
  74. import 'assets/js/china.js'
  75. import { DEFAULT_ECHARTS_THEME } from 'app/globalConstants'
  76. echarts.registerTheme('default', DEFAULT_ECHARTS_THEME)
  77. import configureStore from './configureStore'
  78. const initialState = {}
  79. const store = configureStore(initialState, history)
  80. const MOUNT_NODE = document.getElementById('app')
  81. const render = (messages) => {
  82. ReactDOM.render(
  83. <Provider store={store}>
  84. <LanguageProvider messages={messages}>
  85. <ConfigProvider locale={zh_CN}>
  86. <ConnectedRouter history={history}>
  87. <App />
  88. </ConnectedRouter>
  89. </ConfigProvider>
  90. </LanguageProvider>
  91. </Provider>,
  92. MOUNT_NODE
  93. )
  94. }
  95. if (module.hot) {
  96. module.hot.accept(['./i18n', 'containers/App'], () => {
  97. ReactDOM.unmountComponentAtNode(MOUNT_NODE)
  98. render(translationMessages)
  99. })
  100. }
  101. interface IWindow extends Window {
  102. Intl: any
  103. __REACT_DEVTOOLS_GLOBAL_HOOK__: any
  104. }
  105. declare const window: IWindow
  106. if (!window.Intl) {
  107. (new Promise((resolve) => {
  108. resolve(import('intl'))
  109. }))
  110. .then(() => Promise.all([
  111. import('intl/locale-data/jsonp/en.js')
  112. ]))
  113. .then(() => render(translationMessages))
  114. .catch((err) => {
  115. throw err
  116. })
  117. } else {
  118. render(translationMessages)
  119. }
  120. // Install ServiceWorker and AppCache in the end since
  121. // it's not most important operation and if main code fails,
  122. // we do not want it installed
  123. if (process.env.NODE_ENV === 'production') {
  124. // disable react developer tools in production
  125. if (window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
  126. window.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject = () => void 0
  127. }
  128. }