-
Notifications
You must be signed in to change notification settings - Fork 10
/
vue.config.js
134 lines (125 loc) · 4.07 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
const webpack = require('webpack');
const fs = require('fs');
const { spawnSync } = require('child_process');
const SentryWebpackPlugin = require('@sentry/webpack-plugin');
setGitInfo();
function getGitCommitHash() {
return spawnSync('git', ['rev-parse', 'HEAD'], { timeout: 2000 }).stdout.toString('utf-8').trim();
}
module.exports = {
// Fix Vuex-typescript in prod: https://github.com/istrib/vuex-typescript/issues/13#issuecomment-409869231
configureWebpack: (config) => {
if (process.env.NODE_ENV === 'production') {
config.optimization.minimizer[0].options.terserOptions = Object.assign(
{},
config.optimization.minimizer[0].options.terserOptions,
{
ecma: 5,
compress: {
keep_fnames: true,
},
warnings: false,
mangle: {
keep_fnames: true,
},
}
);
config.plugins.push(
new webpack.ContextReplacementPlugin(
/highlight\.js\/lib\/languages$/,
new RegExp(`^./(${['javascript', 'python', 'bash'].join('|')})$`)
)
);
if (process.env.SENTRY_AUTH_TOKEN) {
config.plugins.push(
new SentryWebpackPlugin({
// sentry-cli configuration - can also be done directly through sentry-cli
// see https://docs.sentry.io/product/cli/configuration/ for details
authToken: process.env.SENTRY_AUTH_TOKEN,
org: 'nomad-research',
project: 'chafan-prod',
release: getGitCommitHash(),
// other SentryWebpackPlugin configuration
include: './dist',
ignore: ['node_modules', 'webpack.config.js'],
})
);
}
config.performance = {
maxEntrypointSize: 512000,
maxAssetSize: 512000,
};
}
config.devtool = 'source-map';
},
chainWebpack: (config) => {
config.module
.rule('vue')
.use('vue-loader')
.loader('vue-loader')
.tap((options) =>
Object.assign(options, {
transformAssetUrls: {
'v-img': ['src', 'lazy-src'],
'v-card': 'src',
'v-card-media': 'src',
'v-responsive': 'src',
},
})
);
},
pwa: {
workboxPluginMode: 'GenerateSW',
workboxOptions: {
exclude: [/\.map$/, /_redirects/],
skipWaiting: true,
},
},
devServer: {
allowedHosts: 'all',
https:
process.env.NODE_ENV === 'production'
? {
key: fs.existsSync('./dev.cha.fan-key.pem')
? fs.readFileSync('./dev.cha.fan-key.pem')
: undefined,
cert: fs.existsSync('./dev.cha.fan.pem')
? fs.readFileSync('./dev.cha.fan.pem')
: undefined,
}
: undefined,
proxy: process.env.NODE_ENV === 'production' ? 'https://dev.cha.fan:8080/' : undefined,
},
};
/** Set git information to process arguments */
function setGitInfo() {
try {
let commit = getGitCommitHash();
let commitTime = spawnSync('git', ['show', '-s', '--format=%cI', 'HEAD'], {
timeout: 2000,
})
.stdout.toString('utf-8')
.trim();
let branch = spawnSync('git', ['branch', '--show-current'], { timeout: 2000 })
.stdout.toString()
.trim();
let tags = spawnSync('git', ['tag', '--points-at', 'HEAD'], { timeout: 2000 })
.stdout.toString()
.trim();
// A single string containing current commit ID
process.env.VUE_APP_GIT_COMMIT = commit;
// A single string containing current branch name
process.env.VUE_APP_GIT_BRANCH = branch;
// A single string containing last commit time
process.env.VUE_APP_GIT_COMMIT_TIME = commitTime;
// A newline-separated string containing all tags applied to this commit,
// or an empty string containing nothing.
process.env.VUE_APP_GIT_TAGS = tags;
console.log('Sending these variables to frontend:');
console.log('Commit: ', commit);
console.log('Branch: ', branch);
console.log('Timestamp: ', commitTime);
} catch (e) {
console.error('Failed to get git version info:', e);
}
}