-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAppShell.js
53 lines (45 loc) · 1.97 KB
/
AppShell.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
import appConfig from 'ROOT/conf.app';
const assetList = require(`${ appConfig.paths.DIST_PUBLIC }/${ appConfig.webpack.MANIFEST_NAME }`);
module.exports = function(model){
const stateScript = model.state && `<script>window.__PRELOADED_STATE__ = ${ model.state };</script>`;
const glamorScript = model.glamor && `<script>window._glam = ${ JSON.stringify(model.glamor.ids) };</script>`;
// allows for hot-reloading
const reloadScript = model.dev && '<script type="text/javascript" src="/reload/reload.js"></script>' || '';
// builds out the list of bundle scripts in the order specified in the config
const bundleScripts = Object.keys(appConfig.webpack.entries).map((key) => {
let ret = `<script type="text/javascript" src="${ assetList[`${ appConfig.webpack.entries[key] }.js`] }"></script>`;
// the chunks should precede the app code to prevent errors during hydration
if(key === 'APP' && model.ssrChunks && model.ssrChunks.length){
let chunkScripts = '';
model.ssrChunks.forEach((chunk) => {
if(chunk){
if(!/\.map/.test(chunk.publicPath)) // don't add `map` files
chunkScripts += `<script type="text/javascript" src="${ chunk.publicPath }"></script>`;
}
});
ret = `${ chunkScripts }${ ret }`;
}
return ret;
});
return `
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>${ model.title }</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="manifest" href="/manifest.json">
<link rel="shortcut icon" href="/media/favicon.png?v=${ model.faviconModTime }">
<style>${ model.css }</style>
${ glamorScript }
${ stateScript }
</head>
<body>
<div id="root" class="root">${ model.body }</div>
${ bundleScripts.join('') }
${ reloadScript }
</body>
</html>
`;
};