-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathentry.js
55 lines (50 loc) · 1.26 KB
/
entry.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
43
44
45
46
47
48
49
50
51
52
53
54
55
import path from 'path'
import React from 'react'
import { render } from 'react-dom'
import App from './App'
require('webpack-serve-overlay')
const req = require.context(DIRNAME, true, /\.(md|mdx|jsx)$/)
const codeContext = require.context('!!raw-loader!' + DIRNAME, true, /\.(md|mdx|jsx)$/)
const routes = req.keys()
.filter(key => !/node_modules/.test(key))
.map(key => {
const extname = path.extname(key)
const name = path.basename(key, extname)
const exact = name === 'index'
const dirname = path.dirname(key).replace(/^\./, '')
const pathname = dirname + '/' + (exact ? '' : name)
let mod, Component
try {
mod = req(key)
Component = mod.default
} catch (err) {
console.error(err)
}
const code = codeContext(key)
if (typeof Component !== 'function') return null
return {
key,
name,
extname,
dirname,
exact,
path: pathname,
Component,
code
}
})
.filter(Boolean)
const providerContext = require.context(DIRNAME, false, /\_app\.js$/)
const Provider = providerContext.keys().length
? providerContext('./_app.js').default
: null
const app = render(
<App
routes={routes}
Provider={Provider}
/>,
root
)
if (module.hot) {
module.hot.accept()
}