-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathvue.config.js
135 lines (125 loc) · 3.99 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
const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const VueSSRClientPlugin = require('vue-server-renderer/client-plugin');
const VueSSRServerPlugin = require('vue-server-renderer/server-plugin');
const resolve = filepath => path.resolve(__dirname, filepath);
const ENABLE_SSR = process.env.VUE_APP_MODE === 'ssr';
const PRODUCTION = process.env.NODE_ENV == 'production';
module.exports = {
lintOnSave: true,
productionSourceMap: true,
devServer: {
proxy: {
'': {
target: process.env.VUE_APP_API_BASE_URL,
secure: false,
changeOrigin: true,
cookieDomainRewrite: 'localhost',
ws: false
},
},
},
chainWebpack: (config) => {
// Treat urls passed to headerIcon as imports
config
.module
.rule('vue')
.use('vue-loader')
.loader('vue-loader')
.tap(options => {
options.transformAssetUrls = {
SidebarPanel: ['headerIcon'],
HeroSection: ['backgroundImage']
};
return options;
});
config
.entry('app')
.clear()
.add('./src/entry-client.ts')
.end();
config
.optimization
.minimizer('terser')
.tap(args => {
const opts = args[0].terserOptions;
opts.mangle = false;
return args;
});
// Derived from https://github.com/jonaskuske/vue-cli-ssr-hmr/blob/7bbb21105c6df964feed158c61a6c546a6741f49/vue.config.js
// (Original license: MIT)
if (ENABLE_SSR) {
// This has to go here so that it gets reevaluated each time the server generates the config, it
// will use the current VUE_APP_ENV, since vue.config.json only gets evaluated once since it's `require()`ed
const IS_SERVER_BUILD = process.env.VUE_APP_ENV === 'server';
config.plugins
// Delete plugins that are unnecessary/broken in SSR & add Vue SSR plugin
.delete('html')
.delete('preload')
.delete('prefetch')
.delete('pwa')
.end()
.plugin('vue-ssr')
.use(IS_SERVER_BUILD ? VueSSRServerPlugin : VueSSRClientPlugin)
.end()
.devtool('source-map');
if (!IS_SERVER_BUILD && !PRODUCTION) {
config.plugin('hmr').use(webpack.HotModuleReplacementPlugin);
}
if (IS_SERVER_BUILD) {
config
// Configure the server-side build that's run in a Node environment
.entry('app')
.clear()
.add('./src/entry-server.ts')
.end()
.target('node')
.devtool('source-map')
.externals(nodeExternals({ allowlist: [/\.css$/, /^vue-bootstrap-breakpoint-indicator/] }))
.output.filename('server-bundle.js')
.libraryTarget('commonjs2')
.end()
.optimization.splitChunks({})
.end()
.plugins.delete('named-chunks')
.delete('hmr')
.delete('workbox');
// Change caching directories so client- and server-side webpack instances
// don't share one cache – otherwise the client build would use cached SSR
// code (and vice versa) and break the build in some cases.
config.module
.rule('vue')
.use('cache-loader')
.tap(cacheConfig => ({
...cacheConfig,
cacheDirectory: resolve(
'./node_modules/.cache/server-bundle/vue-loader',
),
}))
.end()
.use('vue-loader')
.tap(loaderConfig => ({
...loaderConfig,
cacheDirectory: resolve(
'./node_modules/.cache/server-bundle/vue-loader',
),
}))
.end()
.end()
.rule('js')
.use('cache-loader')
.tap(cacheConfig => ({
...cacheConfig,
cacheDirectory: resolve(
'./node_modules/.cache/server-bundle/babel-loader',
),
}));
}
}
},
css: {
sourceMap: true,
extract: false,
},
};