-
Notifications
You must be signed in to change notification settings - Fork 2
/
vue.config.js
53 lines (47 loc) · 1.46 KB
/
vue.config.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
const IS_PROD = process.env.NODE_ENV === "production"
const PrerenderSPAPlugin = require("prerender-spa-plugin")
const Renderer = PrerenderSPAPlugin.PuppeteerRenderer
const path = require("path")
// Import routes to prerender
const prerenderRoutes = require("./prerender-routes")
const routes = ["/", "/blog"].concat(prerenderRoutes)
// For pre-rendering inside Docker
const isPuppeteerUser = require("os").userInfo().username === "pptruser"
// Options for pre-rendering
const prerenderOptions = {
staticDir: path.join(__dirname, "dist"),
routes,
renderer: new Renderer({
renderAfterTime: 5000,
headless: true,
}),
postProcess(context) {
context.html = context.html.replace(`id="app"`, `id="app" data-server-rendered="true"`)
return context
}
}
// Apply different puppeteer settings if in Docker or on local machine
if (IS_PROD) {
if (isPuppeteerUser) {
console.log("isPuppeteerUser: true -- assuming this is a Docker container")
prerenderOptions.renderer = new Renderer({
executablePath: "/usr/bin/chromium-browser",
renderAfterTime: 5000,
headless: true,
args: ['--disable-dev-shm-usage'],
})
} else {
console.log("isPuppeteerUser: false -- prerendering with local google-chrome")
}
}
// Use PrerenderSPAPlugin when building for production
module.exports = {
configureWebpack: config => {
if (!IS_PROD) return
return {
plugins: [
new PrerenderSPAPlugin(prerenderOptions),
],
}
},
}