-
Notifications
You must be signed in to change notification settings - Fork 346
/
vue.config.js
107 lines (98 loc) · 3.26 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
const path = require('path')
const version = require('./package.json').version
const fs = require('fs')
const NODE_ENV = process.env.NODE_ENV
let publicPath = '/'
let outputDir = 'dist'
let appFileName = 'Demo'
if (NODE_ENV === 'demo') {
publicPath = '/workflow-bpmn-modeler/demo/'
outputDir = 'docs/demo'
appFileName = 'Demo'
}
if (NODE_ENV === 'cdn') {
const cdnVersionList = fs.readdirSync('./docs/cdn')
if (cdnVersionList.includes(version)) {
throw new Error(`cdn 版本 ${version} 已存在`)
}
publicPath = `https://cdn.jsdelivr.net/gh/nayacco/workflow-bpmn-modeler@${version}/docs/cdn/${version}/`
outputDir = `docs/cdn/${version}`
appFileName = 'Lib'
}
if (NODE_ENV === 'lib') {
const libVersionList = fs.readdirSync('./docs/lib')
if (libVersionList.includes(version)) {
throw new Error(`lib 版本 ${version} 已存在`)
}
publicPath = './'
outputDir = `docs/lib/${version}`
appFileName = 'Lib'
}
const mainFileStr = `
import Vue from 'vue'
import App from './${appFileName}.vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.config.productionTip = false
Vue.use(ElementUI)
new Vue({
render: h => h(App)
}).$mount('#app')
`
fs.writeFileSync('./src/main.js', mainFileStr)
const resolve = dir => {
return path.join(__dirname, dir)
}
module.exports = {
css: {
loaderOptions: {
sass: {
// 配置全局样式变量
}
}
},
publicPath: publicPath,
outputDir: outputDir,
// tweak internal webpack configuration.
// see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
// 如果你不需要使用eslint,把lintOnSave设为false即可
lintOnSave: true,
chainWebpack: config => {
config.resolve.alias
.set('views', resolve('src/views'))
config
.when(NODE_ENV !== 'development' && NODE_ENV !== 'build',
config => {
config
.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
libs: {
name: 'chunk-libs',
test: /[\\/]node_modules[\\/]/,
priority: 10,
chunks: 'initial' // only package third parties that are initially dependent
},
elementUI: {
name: 'chunk-elementUI', // split elementUI into a single package
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
},
vue: {
name: 'chunk-vue', // split elementUI into a single package
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
test: /[\\/]node_modules[\\/]_?vue(.*)/ // in order to adapt to cnpm
}
}
})
config.optimization.runtimeChunk('single')
}
)
},
// 设为false打包时不生成.map文件
productionSourceMap: false,
// 这里写你调用接口的基础路径,来解决跨域,如果设置了代理,那你本地开发环境的axios的baseUrl要写为 '' ,即空字符串
devServer: {
proxy: 'http://localhost:9527'
}
}