-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.js
273 lines (270 loc) · 8.97 KB
/
vite.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import path from 'path-browserify'
import fs from 'fs'
import { defineConfig, loadEnv } from 'vite'
import { createVuePlugin } from 'vite-plugin-vue2'
import { createHtmlPlugin } from 'vite-plugin-html'
import styleImport from 'vite-plugin-style-import'
import replace from '@rollup/plugin-replace'
import eslintPlugin from 'vite-plugin-eslint'
import cesium from 'vite-plugin-cesium'
// import resolveExternalsPlugin from 'vite-plugin-resolve-externals'
export const hash = Math.floor(Math.random() * 90000) + 10000
// 参考vite-plugin-antdv1-momentjs-resolver插件,修改正则表达式,兼容Windows路径
// https://github.com/carl-jin/vite-plugin-antdv1-momentjs-resolver/blob/main/src/index.js
// 将moment_util.js中import * as moment from moment修改import moment from moment
// 原正则表达式
// const antdvDefaultReg = /ant-design-vue\/[\w-\\\/]*\.js$/
// 修改后正则表达式
// const antdvDefaultReg = /ant-design-vue[\/|\\][\w-\\\/]*\.js$/
const AntdMomentResolver = (reg = /ant-design-vue[\/|\\][\w-\\\/]*\.js$/) => {
return {
name: 'vite-plugin-antdv1-momentjs-resolver',
configResolved(config) {
// 以来预构建时候替换 esbuild
config.optimizeDeps.esbuildOptions.plugins = config.optimizeDeps.esbuildOptions.plugins ? config.optimizeDeps.esbuildOptions.plugins : []
config.optimizeDeps.esbuildOptions.plugins.push({
name: 'replace-code',
setup(build) {
build.onLoad(
{
filter: reg
},
args => {
// 首先获取源代码内容
let source = fs.readFileSync(args.path, 'utf8')
if (source.indexOf('import * as moment from')) {
source = source.replace(/import\s\*\sas\smoment\sfrom/g, 'import moment from')
}
// 替换List组件代码,List.Item为undefined
//if (source.indexOf('Vue.component(List.Item.name, List.Item);')) {
// source = source.replace(
// 'Vue.component(List.Item.name, List.Item);',
// 'Vue.component("AListItem", Item);'
// )
//}
//if (source.indexOf('Vue.component(List.Item.Meta.name, List.Item.Meta);')) {
// source = source.replace(
// 'Vue.component(List.Item.Meta.name, List.Item.Meta);',
// 'Vue.component("AListItemMeta", Item.Meta);'
// )
//}
return {
contents: source
}
}
)
}
})
// 添加打包时的替换 rollup
config.plugins.push(
replace({
values: {
'import * as moment from': id => {
return 'import moment from'
}
},
include: [reg],
preventAssignment: true
})
)
}
}
}
export default ({ mode }) => {
const env = loadEnv(mode, process.cwd())
return defineConfig({
define: {
'process.env': { ...env }
},
plugins: [
// resolveExternalsPlugin({
// Cesium: 'Cesium'
// }),
cesium(),
createVuePlugin({
jsx: true
}),
AntdMomentResolver(),
eslintPlugin(),
createHtmlPlugin({
minify: true,
inject: {
data: {
title: '啓思',
cdn: {
css: [],
js: [
'https://cdn.staticfile.org/vue/2.6.10/vue.min.js',
'https://cdn.staticfile.org/vue-router/3.1.3/vue-router.min.js',
'https://cdn.staticfile.org/vuex/3.1.1/vuex.min.js',
'https://cdn.staticfile.org/axios/0.19.0/axios.min.js',
'https://cdn.staticfile.org/xlsx/0.17.0/xlsx.full.min.js'
]
}
}
}
}),
styleImport({
libs: [
{
libraryName: 'ant-design-vue',
esModule: true,
resolveStyle: name => {
return `ant-design-vue/es/${name}/style/index`
}
},
{
libraryName: 'element-ui',
//styleLibraryName: 'theme-chalk',
esModule: true,
resolveStyle: name => {
return `theme-chalk/${name}.css`
}
}
]
})
],
resolve: {
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
alias: [
{
find: /@\/.+/,
replacement: val => {
return val.replace(/^@/, path.resolve(__dirname, './src/'))
}
}
]
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
// additionalData: `@import "./node_modules/ant-design-vue/lib/style/index.less";
// @import "./node_modules/ant-design-vue/es/style/themes/default.less";`,
// additionalData: `@import "${path.resolve(__dirname, 'src/assets/style/global.less')}";`,
modifyVars: {
'ant-prefix': 'ant',
'ant-pro-prefix': 'ant-pro',
'ant-pro-page-header-wrap': 'ant-pro-page-header-wrap',
'sider-menu-prefix-cls': 'ant-pro-sider-menu',
'basicLayout-prefix-cls': 'ant-pro-basicLayout',
'footer-toolbar-prefix-cls': 'ant-pro-footer-toolbar',
'multi-tab-prefix-cls': 'ant-pro-multi-tab',
'multi-tab-wrapper-prefix-cls': 'ant-pro-multi-tab-wrapper',
'top-nav-header-prefix-cls': 'ant-pro-top-nav-header',
'pro-layout-fixed-header-prefix-cls': 'ant-pro-fixed-header',
'global-footer-prefix-cls': 'ant-pro-global-footer',
'global-header-prefix-cls': 'ant-pro-global-header',
'pro-header-bg': '#fff',
'grid-content-prefix-cls': 'ant-pro-grid-content',
'ant-pro-setting-drawer': 'ant-pro-setting-drawer',
'layout-header-height': '64px',
'ant-global-sider-zindex': 106,
'ant-global-header-zindex': 105,
'primary-color': '#348ee4',
hack: `true; @import (reference) "${path.resolve('src/assets/style/global.less')}";`
}
},
styl: {
additionalData: `@import "${path.resolve(__dirname, 'src/assets/style/global.styl')}";`
}
}
},
build: {
target: 'es2015',
cssTarget: 'chrome80',
brotliSize: false,
chunkSizeWarningLimit: 2000,
commonjsOptions: {
// 改为 ture 后就会转化 require 语法
transformMixedEsModules: true
},
rollupOptions: {
// // 确保外部化处理那些你不想打包进库的依赖
// external: ['vue', 'vue-router', 'vuex', 'axios', 'xlsx'],
// output: {
// // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
// globals: {
// vue: 'Vue',
// 'vue-router': 'VueRouter',
// vuex: 'Vuex',
// axios: 'axios',
// xlsx: 'XLSX'
// }
// }
output: {
entryFileNames: `[name]` + hash + `.js`,
chunkFileNames: `[name]` + hash + `.js`,
assetFileNames: `[name]` + hash + `.[ext]`
}
}
},
server: {
proxy: {
'/api-qs': {
target: `http://127.0.0.1:8080`,
changeOrigin: true,
rewrite: path => path.replace(/^\/api\-qs/, '')
},
// 流程设计
'/flow-api': {
target: `http://127.0.0.1:8080`,
changeOrigin: true,
rewrite: path => path.replace(/^\/flow\-api/, '')
},
// 文档资源访问
'/profile': {
target: `http://127.0.0.1:8080`,
changeOrigin: true
},
// websocket
'/websocket': {
target: `ws://127.0.0.1:8087`,
changeOrigin: true,
ws: true,
rewrite: path => path.replace(/^\/websocket/, '')
},
// pdfjs-viewer
'/pdfjs': {
target: `http://127.0.0.1:8008`,
changeOrigin: true,
rewrite: path => path.replace(/^\/pdfjs/, '')
},
// 百度OCR
'/baidu-api': {
target: `https://aip.baidubce.com`,
changeOrigin: true,
rewrite: path => path.replace(/^\/baidu\-api/, '')
},
// #region
// lool start
'/loleaflet': {
target: `http://127.0.0.1:9980`,
changeOrigin: true
},
'/hosting/discovery': {
target: `http://127.0.0.1:9980`,
changeOrigin: true
},
'/hosting/capabilities': {
target: `http://127.0.0.1:9980`,
changeOrigin: true
},
'^/lool/(.*)/ws$': {
target: `http://127.0.0.1:9980`,
changeOrigin: true
},
'^/lool': {
target: `http://127.0.0.1:9980`,
changeOrigin: true
},
'/lool/adminws': {
target: `http://127.0.0.1:9980`,
changeOrigin: true
}
// lool end
// #endregion
}
}
})
}