forked from based-ghost/vue-seo-friendly-spa-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
86 lines (79 loc) · 2.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* eslint-disable no-param-reassign,import/no-extraneous-dependencies */
const path = require("path");
const cheerio = require("cheerio");
const PrerenderSPAPlugin = require("prerender-spa-plugin");
module.exports = {
// https://github.com/visualfanatic/vue-svg-loader
chainWebpack: config => {
const svgRule = config.module.rule("svg");
svgRule.uses.clear();
svgRule
.use("babel-loader")
.loader("babel-loader")
.end()
.oneOf("inline")
.resourceQuery(/inline/)
.use("vue-svg-loader")
.loader("vue-svg-loader")
.end()
.end()
.oneOf("external")
.use("file-loader")
.loader("file-loader")
.options({
name: "assets/[name].[hash:8].[ext]",
svgo: {
plugins: [{ prefixIds: true }]
}
});
},
// https://cli.vuejs.org/guide/webpack.html
configureWebpack: config => {
if (process.env.NODE_ENV !== "production") {
return {};
}
return {
devtool: false,
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
},
plugins: [
// https://github.com/chrisvfritz/prerender-spa-plugin
new PrerenderSPAPlugin({
staticDir: config.output.path,
routes: ["/", "/about", "/404"],
renderAfterDocumentEvent: 'prerender-event',
renderer: new PrerenderSPAPlugin.PuppeteerRenderer({}),
postProcess(context) {
if (context.route === "/404") {
context.outputPath = path.join(config.output.path, "/404.html");
}
// Remove google analytics script (will be readded by client)
// Add data-server-rendered="true" to #app (dynamically add here rather than hard code in index.html)
const $ = cheerio.load(context.html);
$('head').children('script[src*="google-analytics"]').remove();
$('#app').attr('data-server-rendered', 'true');
context.html = $.html();
return context;
}
})
]
};
},
// https://github.com/vuejs/vue-cli/tree/dev/packages/@vue/cli-plugin-pwa
pwa: {
name: "VueSeoFriendlySpaTemplate",
themeColor: "#fff",
msTileColor: "#fff",
workboxPluginMode: "GenerateSW",
workboxOptions: {
skipWaiting: true,
cacheId: "VueSeoSpa",
importWorkboxFrom: "local",
navigateFallback: "/index.html",
navigateFallbackWhitelist: [/^((?!\/404).)*$/]
}
}
};