-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev.js
42 lines (39 loc) · 1.31 KB
/
dev.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Component } from "react"
import { render } from "react-dom"
import extend from "extend"
// common script
// require('./view/pc/entry.js')
// or
// require('./view/mobile/entry.js')
// entry
switch(location.pathname) {
case '/example':
require(['./view/example/app'], renderComponent())
break
case '/view/example/index.html':
require(['./view/example/app'], renderComponent())
break
case '/m/example/README.html':
require(['./m/example/index.demo.js'], renderComponent())
break
case '/view/redux/index.html':
require(['./view/redux/app'], renderComponent())
break
default:
console.log('/dev.js not match ' + location.pathname)
}
function renderComponent (settings) {
var defaultSettins = {
renderNode: document.getElementById('app'),
props: {}
}
settings = extend(true, defaultSettins, settings)
if (typeof settings.renderNode === 'string') {
settings.renderNode = document.getElementById(settings.renderNode)
}
return function (Component) {
let App = typeof Component.default !== 'undefined'? Component.default :Component
if (typeof settings.renderNode === 'undefined') { throw new Error('/dev.js not find renderNode') }
render(<App {...settings.props} />, settings.renderNode)
}
}