This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
142 lines (135 loc) · 4.01 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
// const CompressionWebpackPlugin = require("compression-webpack-plugin");
// const zopfli = require("@gfx/zopfli");
// const BrotliPlugin = require("brotli-webpack-plugin");
const PrerenderSpaPlugin = require("prerender-spa-plugin");
// const productionGzipExtensions = /\.(js|css|json|txt|html)(\?.*)?$/i;
const isProduction = process.env.NODE_ENV === 'production'
const needBundleAnalysis = process.argv.includes('--analyze')
const resolve = dir => path.join(__dirname, dir);
const renderRoutes = (() => {
const routes = [
'/',
// '/welcome',
// '/imgur'
// '/dashboard',
// '/login',
// '/registration',
// '/admin',
// '/fixing'
].map((route) => route.replace(/\/$/, ''))
routes.push(...routes.map((route) => `${route}/`))
return routes
})()
module.exports = {
chainWebpack: config => {
if (isProduction && needBundleAnalysis) {
config.plugin('analyzer').use(new BundleAnalyzerPlugin())
}
config.performance
.maxEntrypointSize(1000000)
.maxAssetSize(1000000)
// config.plugin('optimize-css').tap(([options]) => {
// options.cssnanoOptions.preset[1].svgo = false
// return [options]
// })
const svgRule = config.module.rule('svg')
svgRule.uses.clear()
config.module
.rule("svg-sprite-loader")
.test(/\.svg$/)
.include
.add(resolve("src/assets/images"))
.add(resolve("src/articles/articleResources"))
.end()
.use("svg-sprite-loader")
.loader("svg-sprite-loader")
.options({symbolId: "[name].svg"})
},
configureWebpack: config => {
const plugins = [];
if (isProduction) {
// plugins.push(
// new CompressionWebpackPlugin({
// algorithm(input, compressionOptions, callback) {
// return zopfli.gzip(input, compressionOptions, callback);
// },
// compressionOptions: {
// numiterations: 15
// },
// minRatio: 0.99,
// test: productionGzipExtensions
// })
// );
// plugins.push(
// new BrotliPlugin({
// test: productionGzipExtensions,
// minRatio: 0.99
// })
// );
plugins.push(
new PrerenderSpaPlugin({
staticDir: resolve("dist"),
routes: renderRoutes,
registry: undefined,
useRenderEvent: true,
onlyProduction: true,
postProcess(renderedRoute) {
renderedRoute.route = renderedRoute.originalRoute
if (renderedRoute.route.endsWith('.html')) {
renderedRoute.outputPath = path.join(__dirname, 'dist', renderedRoute.route)
}
return renderedRoute
},
minify: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
decodeEntities: true,
keepClosingSlash: true,
sortAttributes: true
},
renderer: new PrerenderSpaPlugin.PuppeteerRenderer({
renderAfterDocumentEvent: "app-rendered",
maxConcurrentRoutes: 20,
headless: true,
})
})
);
}
config.plugins = [...config.plugins, ...plugins];
},
pages: {
index: {
entry: "src/main.ts",
template: 'public/index.html',
filename: 'index.html',
title: "NPC 北科程式設計研究社",
chunks: ['chunk-vendors', 'chunk-common', 'index']
}
},
productionSourceMap: false,
css: {
sourceMap: false,
},
lintOnSave: process.env.NODE_ENV === 'development',
pluginOptions: {
prerenderSpa: {
registry: undefined,
renderRoutes: [
'/',
// '/welcome',
// '/imgur'
// '/dashboard',
// '/login',
// '/registration',
// '/admin',
// '/fixing'
],
useRenderEvent: true,
headless: true,
onlyProduction: true
}
}
}