@@ -9,7 +9,7 @@ import React from 'react';
9
9
import ReactDOMServer from 'react-dom/server' ;
10
10
import { renderStatic } from 'glamor/server' ;
11
11
import HTML from './templates/HTML' ;
12
- import App from './templates/App' ;
12
+ import App , { buildRoutes } from './templates/App' ;
13
13
14
14
const PORT = 3031 ;
15
15
@@ -62,52 +62,12 @@ function collectInfo() {
62
62
63
63
collectInfo ( ) ;
64
64
65
- fs . writeFileSync (
66
- path . join ( dist , 'app.src.js' ) ,
67
- `
68
- import React from 'react';
69
- import ReactDOM from 'react-dom';
70
- import RedBox from 'redbox-react';
71
- import { rehydrate } from 'glamor';
72
- import App from '../templates/App';
73
- import pages from './app.data.json';
74
-
75
- rehydrate(window.__GLAMOR__);
76
-
77
- const root = document.getElementById('root')
78
- const render = () => {
79
- try {
80
- ReactDOM.render(
81
- <App
82
- pages={pages}
83
- name={window.__INITIAL_PATH__}
84
- />,
85
- root
86
- );
87
- } catch (e) {
88
- ReactDOM.render(
89
- <RedBox error={ error } />,
90
- root
91
- )
92
- }
93
- }
94
-
95
- if (module.hot) {
96
- module.hot.accept(() => {
97
- setTimeout(render)
98
- })
99
- }
100
-
101
- render()
102
- ` ,
103
- ) ;
104
-
105
- function buildHTML ( { title, description, filename } : any ) {
65
+ function buildHTML ( { title, description, name } : any ) {
106
66
const { html, css, ids } = renderStatic (
107
67
( ) => ReactDOMServer . renderToString (
108
68
< App
109
69
pages = { items }
110
- name = { filename }
70
+ name = { name }
111
71
/>
112
72
)
113
73
) ;
@@ -116,19 +76,19 @@ function buildHTML({ title, description, filename }: any) {
116
76
117
77
body += `
118
78
<script>
119
- window.__INITIAL_PATH__ = '${ filename } '
79
+ window.__INITIAL_PATH__ = '${ name } '
120
80
window.__GLAMOR__ = ${ JSON . stringify ( ids ) }
121
81
</script>
122
82
` ;
123
83
124
84
if ( task === 'build' ) {
125
- body += '<script src=\' app.bundle.js?transpile=false\' ></script>' ;
85
+ body += '<script src="./ app.bundle.js?transpile=false" ></script>' ;
126
86
} else {
127
- body += '<script src=\' app.src.js\' ></script>' ;
87
+ body += '<script src="../ app.src.js" ></script>' ;
128
88
}
129
89
130
90
fs . writeFileSync (
131
- path . join ( dist , `${ filename } .html` ) ,
91
+ path . join ( dist , `${ name } .html` ) ,
132
92
ReactDOMServer . renderToString (
133
93
// eslint-disable-next-line react/jsx-pascal-case
134
94
< HTML
@@ -141,19 +101,9 @@ function buildHTML({ title, description, filename }: any) {
141
101
) ;
142
102
}
143
103
144
- items . forEach ( it => buildHTML ( {
145
- title : it . name ,
146
- description : it . info . description ,
147
- filename : it . name . toLowerCase ( ) ,
148
- } ) ) ;
149
-
150
- buildHTML ( {
151
- title : 'Home' ,
152
- description : '' ,
153
- filename : 'index' ,
154
- } ) ;
104
+ buildRoutes ( items ) . forEach ( buildHTML ) ;
155
105
156
- const entry = [ 'dist/ app.src.js' ] ;
106
+ const entry = [ 'app.src.js' ] ;
157
107
158
108
if ( task !== 'build' ) {
159
109
watch ( path . join ( __dirname , '../src' ) , ( ) => {
0 commit comments