-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvue.config.util.js
54 lines (53 loc) · 2.07 KB
/
vue.config.util.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
// noinspection NpmUsedModulesInstalled
const { info } = require('@vue/cli-shared-utils')
module.exports = {
/**
* Generate public path by environment.
*
* ATTENTION: Relative path prefix should start with a dot './'.
* DON'T add the dot when the environment is development, or browser will throw en error like this:
* Uncaught SyntaxError: Unexpected token <
* @return {string} public path.
*/
generatePublicPath: () => {
const runOnDocker = process.env.VUE_APP_RUN_ON_DOCKER
info(`This application is running on Docker: ${runOnDocker}, type of runOnDocker: ${typeof runOnDocker}`)
const pathPrefix = runOnDocker === 'true' ? './' : '/'
info(`pathPrefix: ${pathPrefix}`)
const vueAppEnv = process.env.VUE_APP_ENV
let publishPath
if (vueAppEnv === 'prod') {
publishPath = pathPrefix
info(`publicPath for [${vueAppEnv}]: ${publishPath}`)
return pathPrefix
}
const applicationName = JSON.parse(unescape(process.env.VUE_APP_PACKAGE_JSON)).name
if (applicationName) {
publishPath = applicationName ? pathPrefix.concat(applicationName, '-', vueAppEnv, '/') : pathPrefix
info(`publicPath for [${vueAppEnv}] with application name: ${publishPath}`)
return publishPath
}
publishPath = pathPrefix
info(`publicPath for [${vueAppEnv}] without application name: ${publishPath}`)
return publishPath
},
/**
* Get app name.
* @return {string} app name.
*/
getAppName: () => {
const applicationName = JSON.parse(unescape(process.env.VUE_APP_PACKAGE_JSON)).name
.replace(/-/g, ' ')
.split(' ')
.map(word => word[0].toUpperCase() + word.substr(1).toLowerCase())
.join(' ')
const vueAppEnv = process.env.VUE_APP_ENV
if (vueAppEnv !== 'prod') {
const nonProductionApplicationName = applicationName.concat(' (', process.env.VUE_APP_ENV, ')')
info(`applicationName: ${nonProductionApplicationName}`)
return applicationName.concat(' (', process.env.VUE_APP_ENV, ')')
}
info(`applicationName: ${applicationName}`)
return applicationName
}
}