Skip to content
This repository was archived by the owner on May 21, 2020. It is now read-only.

Commit 7a1f09c

Browse files
committed
refactor(Html): re/moved unecessary code
1 parent 68e1245 commit 7a1f09c

File tree

1 file changed

+43
-25
lines changed

1 file changed

+43
-25
lines changed

src/server/components/Html.jsx

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,10 @@ import React, { PropTypes as PT, PureComponent } from 'react'
44
import fs from 'fs'
55
import { publicDir } from '../../../config/paths'
66
import { renderToStaticMarkup } from 'react-dom/server'
7-
import { version } from '../../../package.json'
87

9-
const encoding = { encoding: 'utf8' }
8+
import './html.css' // eslint-disable-line sort-imports
109

11-
import './html.css'
12-
13-
export default class Html extends Component {
14-
15-
static propTypes = {
16-
app: PT.string.isRequired,
17-
content: PT.string.isRequired,
18-
initalState: PT.object.isRequired,
19-
inline: DEBUG ? PT.bool.isRequired : PT.string.isRequired,
20-
vendor: PT.string.isRequired
21-
}
22-
23-
static defaultProps = {
24-
app: Html.getScript(appName),
25-
vendor: Html.getScript(vendorName),
26-
inline: Html.getWebpackJsonpInlineScript()
27-
}
10+
class Html extends PureComponent {
2811

2912
static getDoctype() {
3013
return '<!doctype html>'
@@ -33,23 +16,25 @@ export default class Html extends Component {
3316
static getScript(name) {
3417
if (DEBUG) return `/${name}.js`
3518

36-
const file = fs.readFileSync(`${publicDir}/${statsName}.json`, encoding)
19+
const file = fs.readFileSync(`${publicDir}/${statsName}.json`)
3720
const stats = JSON.parse(file)
3821

39-
return `/${stats.assetsByChunkName[name]}`
22+
return name === 'app' && !DEBUG
23+
? `/${stats.assetsByChunkName[name][0]}`
24+
: `/${stats.assetsByChunkName[name]}`
4025
}
4126

4227
static getWebpackJsonpInlineScript() {
4328
if (DEBUG) return false
44-
return fs.readFileSync(`${publicDir}/${inlineName}.js`, encoding)
29+
return fs.readFileSync(`${publicDir}/${inlineName}.js`)
4530
}
4631

4732
static renderToStaticMarkup(props) {
4833
return Html.getDoctype() + renderToStaticMarkup(<Html {...props}/>)
4934
}
5035

5136
render() {
52-
const { app, content, inline, vendor, initalState } = this.props
37+
const { app, content, initalState, inline, vendor } = this.props
5338

5439
return (
5540
<html
@@ -82,20 +67,53 @@ export default class Html extends Component {
8267
<meta content='true' name='HandheldFriendly'/>
8368
<meta content='320' name='MobileOptimized'/>
8469

85-
<link href='/style.css' rel='stylesheet'/>
70+
<link href='/apple-icon-57x57.png' rel='apple-touch-icon' sizes='57x57'/>
71+
<link href='/apple-icon-60x60.png' rel='apple-touch-icon' sizes='60x60'/>
72+
<link href='/apple-icon-72x72.png' rel='apple-touch-icon' sizes='72x72'/>
73+
<link href='/apple-icon-76x76.png' rel='apple-touch-icon' sizes='76x76'/>
74+
<link href='/apple-icon-114x114.png' rel='apple-touch-icon' sizes='114x114'/>
75+
<link href='/apple-icon-120x120.png' rel='apple-touch-icon' sizes='120x120'/>
76+
<link href='/apple-icon-144x144.png' rel='apple-touch-icon' sizes='144x144'/>
77+
<link href='/apple-icon-152x152.png' rel='apple-touch-icon' sizes='152x152'/>
78+
<link href='/apple-icon-180x180.png' rel='apple-touch-icon' sizes='180x180'/>
79+
<link href='/android-icon-192x192.png' rel='icon' sizes='192x192' type='image/png'/>
80+
<link href='/favicon-32x32.png' rel='icon' sizes='32x32' type='image/png'/>
81+
<link href='/favicon-96x96.png' rel='icon' sizes='96x96' type='image/png'/>
82+
<link href='/favicon-16x16.png' rel='icon' sizes='16x16' type='image/png'/>
83+
84+
<meta content='#ffffff' name='msapplication-TileColor'/>
85+
<meta content='/ms-icon-144x144.png' name='msapplication-TileImage'/>
86+
<meta content='#ffffff' name='theme-color'/>
8687

88+
<link href='/style.css' rel='stylesheet'/>
8789
</head>
8890
<body>
8991
<div id='app'>
9092
<div dangerouslySetInnerHTML={{ __html: content }}/>
9193
</div>
9294

95+
<script dangerouslySetInnerHTML={{ __html: `window.__INITAL_STATE__ = ${JSON.stringify(initalState)}` }}/>
9396
{inline && <script dangerouslySetInnerHTML={{ __html: inline }}/>}
94-
<script dangerouslySetInnerHTML={{ __html: `window.__INITIAL_STATE__=${JSON.stringify(initalState)}` }}/>
9597
<script src={vendor}/>
9698
<script src={app}/>
9799
</body>
98100
</html>
99101
)
100102
}
101103
}
104+
105+
Html.propTypes = {
106+
app: PT.string.isRequired,
107+
content: PT.string.isRequired,
108+
initalState: PT.object.isRequired,
109+
vendor: PT.string.isRequired,
110+
inline: DEBUG ? PT.bool : PT.string,
111+
}
112+
113+
Html.defaultProps = {
114+
app: Html.getScript(appName),
115+
vendor: Html.getScript(vendorName),
116+
inline: Html.getWebpackJsonpInlineScript(),
117+
}
118+
119+
export default Html

0 commit comments

Comments
 (0)