-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
213 lines (207 loc) · 8.33 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
const path = require('path')
const dayjs = require('dayjs')
const { queryBuildConfig } = require('./build/buildConfig.js')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const FileManagerPlugin = require('filemanager-webpack-plugin')
var plugins = []
const pages = {}
function resolve (dir) {
return path.join(__dirname, dir)
}
process.env.VUE_APP_build = dayjs().format('YYYY-MM-DD HH:mm')
const NODE_ENV = process.env.NODE_ENV
const isAdminMode = process.env.VUE_APP_isAdmin === 'true' // WordPress后台插件的开发模式
console.log(NODE_ENV, isAdminMode ? 'wp编辑器' : 'C端')
// console.log(process.env)
const { buildType = 'cats-upload-all', theme = 'plans', h5URL, sourceMap } = queryBuildConfig()
console.log(buildType, theme)
process.env.VUE_APP_theme = theme
const alias = {
'vue$': 'vue/dist/vue.esm-bundler.js',
'@public': resolve('public'),
'@': resolve('src'),
'@api': resolve('src/api'),
'@m': resolve('src/themes/mt4'),
'@c': resolve('src/themes/cats'),
'@ct': resolve('src/themes/ctrader'),
'@abcc': resolve('src/themes/abcc'),
'@plans': resolve('src/themes/plans'),
'@planspc': resolve('src/themes/plans_PCUI'),
'@admin': resolve('src_admin'),
'@utils': resolve('src_admin/utils'),
'@index': resolve('src_admin/pages/index'),
'@h5': resolve(`src/themes/${theme}`),
'@w': resolve('src/themes/webview'),
}
if (process.env.NODE_ENV === 'production') {
const pluginName = isAdminMode ? 'editor' : 'h5'
const packageName = isAdminMode ? 'cats-upload-admin' : 'cats-upload-h5' // zip包名字
const outputDirDestination = `/build_folder/${packageName}/${packageName}/dist/skin_${theme}_2`
const wp_init_file = isAdminMode ? 'init_editor.ini' : 'init_h5.ini'
plugins.push(
new FileManagerPlugin({
events: {
onEnd: {
// delete: [
// `./build_folder/${pathStr}/${pathStr}/dist`,
// `./build_folder/${pathStr}.zip`
// ],
copy: [{
source: resolve('/build_folder/dist'),
destination: resolve(outputDirDestination) + `/${pluginName}`
}, {
source: resolve(`/src/themes/${theme}/${wp_init_file}`),
destination: resolve(outputDirDestination) + `/${wp_init_file}`
}],
archive: [
// { source: resolve(`${pathName}`), destination: resolve(`zip/${pathName}${dayjs().format('YYYYMMDDHHmm')}.zip`) },
{
source: resolve(`./build_folder/${packageName}`),
destination: `./build_folder/${packageName}.zip`,
options: {
gzipOptions: {
level: 1
}
}
}
],
}
}
})
)
// 编译前清空旧的编译文件
plugins.push(new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [resolve(`${outputDirDestination}/**`)],
}))
}
if (isAdminMode) {
// WordPress后台插件的开发模式
Object.assign(pages, {
index: {
entry: 'src_admin/pages/index/main.js',
template: 'public/admin.html',
filename: 'index.html',
},
// preview: {
// entry: 'src_admin/pages/preview/main.js',
// template: 'public/preview.html',
// filename: 'preview.html',
// }
})
} else {
// H5开发模式
Object.assign(pages, {
index: {
entry: `src/themes/${theme}/main.js`,
template: 'public/index.html',
filename: process.env.NODE_ENV === 'production' ? 'index_template.html' : 'index.html',
},
upgrading: {
entry: 'src/themes/upgrading/main.js',
template: 'public/index.html',
filename: process.env.NODE_ENV === 'production' ? 'upgrading.html' : 'upgrading.html',
}
// index: 'src/themes/mt4/main.js'
// index: 'src/themes/ctrader/main.js'
})
}
const config = {
productionSourceMap: sourceMap === 'true',
publicPath: process.env.NODE_ENV === 'production' && isAdminMode ? `/wp-content/plugins/cats-manage/skin/skin_${theme}_2/editor/` : '/', // static/
// indexPath: isAdminMode ? 'index.html' : 'index_template.html', // 就是这条
lintOnSave: false,
outputDir: isAdminMode ? './build_folder/dist' : './build_folder/dist',
configureWebpack: {
plugins,
optimization: {
splitChunks: {
cacheGroups: {
default: false
}
}
},
// provide the app's title in webpack's name field, so that
// it can be accessed in index.html to inject the correct title.
resolve: {
alias
}
},
css: {
loaderOptions: { // 自动注入全局变量样式
sass: {
// 注意: 在 sass-loader v8 中,这个选项是 prependData
prependData: '@import "~@/sass/mixin.scss";',
},
},
},
devServer: {
port: isAdminMode ? 8080 : 8090,
open: false,
overlay: {
warnings: false,
errors: true
},
proxy: {
'/wp-content/uploads': {
target: h5URL || 'https://prewpadmin_10.cats-trade.com',
},
'/wp-json/wp': {
target: 'http://prewpadmin_9.cats-trade.com', // http://prewpadmin.cats-trade.com/
// changeOrigin: false,
disableHostCheck: true,
onProxyReq: function (proxyReq, req, res, options) { // 由于vue中使用了body-parser 导致http中的body被序列化两次,从而使得配置代理后后端无法获取body中的数据
if (req.body) {
const reg = new RegExp('application/json')
if (reg.test(proxyReq.getHeader('Content-Type'))) {
const bodyData = JSON.stringify(req.body)
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData))
// stream the content
proxyReq.write(bodyData)
}
}
}
},
'/cats-manage-api': {
target: h5URL || 'https://uatwph5-5.cats-trade.com', // prewph5公司id为2 prewph5_1公司id为60 'http://prewph5_9.cats-trade.com' // h5URL
disableHostCheck: true,
onProxyReq: function (proxyReq, req, res, options) { // 由于vue中使用了body-parser 导致http中的body被序列化两次,从而使得配置代理后后端无法获取body中的数据
if (req.body) {
const reg = new RegExp('application/json')
if (reg.test(proxyReq.getHeader('Content-Type'))) {
const bodyData = JSON.stringify(req.body)
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData))
// stream the content
proxyReq.write(bodyData)
}
}
}
},
'/upload': {
target: 'https://uatcom-03b1ee05fa3b4fcbe21e9da72e5516cd-prebo.cats-trade.com/cats-gateway/upload'
}
},
before: require('./mock/mock-server.js')
},
chainWebpack: config => {
// 移除 prefetch 插件
config.plugins.delete('preload-index').delete('prefetch-index')
config.resolve.alias.set('vue-i18n', 'vue-i18n/dist/vue-i18n.cjs.js')
},
pages
}
// uniapp图表详情页面插件打包功能
const argv = require('minimist')(process.argv.slice(2))
if (argv && argv.type === 'webview') {
Object.assign(config, {
publicPath: './',
productionSourceMap: false,
pages: {
webview: {
entry: 'src/themes/webview/main.js',
template: 'public/webview.html',
filename: 'webview.html',
}
}
})
}
module.exports = config