forked from quasarframework/quasar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.prod-webserver.js
70 lines (57 loc) · 1.79 KB
/
template.prod-webserver.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* THIS FILE IS GENERATED AUTOMATICALLY.
* DO NOT EDIT.
**/
const fs = require('fs')
const path = require('path')
const LRU = require('lru-cache')
const { createBundleRenderer } = require('vue-server-renderer')
const resolve = file => path.join(__dirname, file)
const template = fs.readFileSync(resolve('template.html'), 'utf-8')
const bundle = require('./quasar.server-manifest.json')
const clientManifest = require('./quasar.client-manifest.json')
const settings = <%= opts %>
<% if (opts.publicPath !== '/') { %>
const doubleSlashRE = /\/\//
const { publicPath } = settings
<% } %>
if (process.env.DEBUG) {
settings.debug = true
}
const rendererOptions = {
template,
clientManifest,
// for component caching
cache: new LRU(settings.componentCache),
basedir: __dirname,
// recommended for performance
runInNewContext: false
}
const resolveUrl = url => <% if (opts.publicPath === '/') { %>url || '/'<% } else { %>url ? (publicPath + url).replace(doubleSlashRE, '/') : publicPath<% } %>
// https://ssr.vuejs.org/api/#renderer-options
// https://github.com/vuejs/vue/blob/dev/packages/vue-server-renderer/README.md#why-use-bundlerenderer
let renderer = createBundleRenderer(bundle, rendererOptions)
module.exports.resolveUrl = resolveUrl
module.exports.renderToString = function (opts, cb) {
const ctx = {
...opts,
url: opts.req.url
}
<% if (flags.meta) { %>
renderer.renderToString(ctx, (err, html) => {
cb(err, err ? html : ctx.$getMetaHTML(html, ctx))
})
<% } else { %>
renderer.renderToString(ctx, cb)
<% } %>
}
module.exports.resolveWWW = function (file) {
return resolve('www/' + file)
}
module.exports.mergeRendererOptions = function (opts) {
renderer = createBundleRenderer(
bundle,
Object.assign(rendererOptions, opts)
)
}
module.exports.settings = settings