packages/build-tools/console-toolkit-plugin-xconsole-fs-route/tpl/app.js.ejs (67 lines of code) (raw):

import React from 'react' import { hot } from 'react-hot-loader' import dva from 'dva' import { Router } from 'dva/router' import createLoading from 'dva-loading' import { createBrowserHistory, createHashHistory } from 'history' import { withProvider, ErrorCenter } from '@alicloud/xconsole' <% if(global.hasUIConfig){ %> // 如果配置了自定义 UI 系统,则使用项目配置 import uis from '~/ui'; <% } else { %> // 使用 console-components 作为 UI 系统 import * as uis from '@alicloud/console-components'; <% } %> <% if(global.hasEntryCode){ %> // 如果有写了 entry 文件,则引入 import entry from '~/app'; <% } %> <% if(global.hasWidgetLoader){ %> // 如果有写了自定义 widgetLoader 逻辑,则引入 import widgetLoader from '~/loader'; <% } %> <% if(global.hasAppConfig){ %> // 如果有运行时配置,则引入 import appConfig from '~/appConfig'; <% } %> import getRoutes from './routes' import '../styles/index.less' // const { register } = RcRegion <% if(!global.hasWidgetLoader){ %> // 未指定自定义 widgetLoader 逻辑 const widgetLoader = null; <% } %> <% if(!global.hasAppConfig){ %> // 没有运行时配置 const appConfig = {} <% } %> // 根据设定,使用 hash 路由或文件路由模式 // 默认情况下,使用文件路由 <% if(global.mode === 'hash'){ %> const _history = createHashHistory(); <% } else { %> const _history = createBrowserHistory(); <% } %> const app = dva({ history: _history }) //app.use(register(app)) app.use(createLoading()) if (appConfig.errorCenter && appConfig.errorCenter.enable) { app.use(ErrorCenter(appConfig.errorCenter)) } const Routes = getRoutes({ history: _history }) app.router(({ history }) => ( <Router history={history}> <Routes /> </Router> )) const OriginApp = withProvider()(app.start()) const App = process.env.NODE_ENV === 'development' ? hot(module)(OriginApp) : OriginApp; <% if (global.hasEntryCode){ %> export default entry(app, App) <% } else { %> export default props => <App {...props} /> <% } %>