-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathvite.config.ts
169 lines (162 loc) · 5.86 KB
/
vite.config.ts
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
import path from 'path';
import vue from '@vitejs/plugin-vue';
import { BilldHtmlWebpackPlugin, logData } from 'billd-html-webpack-plugin';
import autoImport from 'unplugin-auto-import/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
import unpluginVueComponents from 'unplugin-vue-components/vite';
import { defineConfig } from 'vite';
import checker from 'vite-plugin-checker';
import electron from 'vite-plugin-electron/simple';
import eslint from 'vite-plugin-eslint2';
import { createHtmlPlugin } from 'vite-plugin-html';
import pkg from './package.json';
const isWeb = process.env['VITE_APP_RELEASE_PROJECT_ISWEB'] === 'true';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const isProduction = mode === 'production';
const outputStaticUrl = () => {
if (isWeb) {
if (isProduction) {
return 'https://tencentcos-res.hsslive.cn/billd-desk/client/dist/';
} else {
return './';
}
} else {
return './';
}
};
return {
base: outputStaticUrl(),
css: {
preprocessorOptions: {
scss: {
additionalData: `@use 'billd-scss/src/index.scss' as *;@import "@/assets/css/constant.scss";`,
},
},
},
resolve: {
alias: { '@': path.resolve(__dirname, 'src') },
/**
* 不建议省略.vue后缀
* https://cn.vitejs.dev/config/shared-options.html#resolve-extensions
*/
// extensions: ['.js', '.ts', '.jsx', '.tsx', '.vue'],
},
build: {
outDir: 'dist',
},
plugins: [
// legacy(),
// isProduction && legacy(),
vue(),
createHtmlPlugin({
inject: {
data: {
// @ts-ignore
title: pkg.productName,
},
},
}),
electron({
main: {
entry: 'electron-main/index.ts', // 主进程文件
vite: {
build: {
outDir: 'electron-dist',
lib: {
entry: 'electron-main/index.ts', // 主进程文件
formats: ['cjs'],
fileName: () => '[name].cjs',
},
},
},
},
preload: {
input: 'electron-main/preload.ts',
vite: {
build: {
outDir: 'electron-dist',
},
},
},
}),
// renderer({
// resolve: {
// '@nut-tree/nut-js': { type: 'cjs' },
// },
// }),
checker({
// typescript: true,
vueTsc: true,
// eslint: {
// lintCommand: 'eslint "./src/**/*.{ts,tsx}"', // for example, lint .ts & .tsx
// },
}),
eslint({}),
autoImport({
imports: [
{
'naive-ui': ['useMessage', 'useNotification'],
},
],
}),
unpluginVueComponents({
// eslint-disable-next-line
resolvers: [NaiveUiResolver()],
}),
new BilldHtmlWebpackPlugin({ env: 'vite4' }).config,
],
define: {
'process.env': {
BilldHtmlWebpackPlugin: logData(null),
NODE_ENV: JSON.stringify(isProduction ? 'production' : 'development'),
PUBLIC_PATH: outputStaticUrl(),
VUE_APP_RELEASE_PROJECT_NAME: JSON.stringify(
process.env.VUE_APP_RELEASE_PROJECT_NAME
),
VUE_APP_RELEASE_PROJECT_ENV: JSON.stringify(
process.env.VUE_APP_RELEASE_PROJECT_ENV
),
VUE_APP_RELEASE_PROJECT_VERSION: JSON.stringify(pkg.version),
},
},
server: {
host: '0.0.0.0',
proxy: {
'/api': {
target: 'http://localhost:4300',
secure: false, // 默认情况下(secure: true),不接受在HTTPS上运行的带有无效证书的后端服务器。设置secure: false后,后端服务器的HTTPS有无效证书也可运行
/**
* changeOrigin,是否修改请求地址的源
* 默认changeOrigin: false,即发请求即使用devServer的localhost:port发起的,如果后端服务器有校验源,就会有问题
* 设置changeOrigin: true,就会修改发起请求的源,将原本的localhost:port修改为target,这样就可以通过后端服务器对源的校验
*/
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '/'),
},
'/betaapi': {
target: 'http://localhost:4300',
secure: false, // 默认情况下(secure: true),不接受在HTTPS上运行的带有无效证书的后端服务器。设置secure: false后,后端服务器的HTTPS有无效证书也可运行
/**
* changeOrigin,是否修改请求地址的源
* 默认changeOrigin: false,即发请求即使用devServer的localhost:port发起的,如果后端服务器有校验源,就会有问题
* 设置changeOrigin: true,就会修改发起请求的源,将原本的localhost:port修改为target,这样就可以通过后端服务器对源的校验
*/
changeOrigin: true,
rewrite: (path) => path.replace(/^\/betaapi/, '/'),
},
'/prodapi': {
target: 'http://localhost:4200',
secure: false, // 默认情况下(secure: true),不接受在HTTPS上运行的带有无效证书的后端服务器。设置secure: false后,后端服务器的HTTPS有无效证书也可运行
/**
* changeOrigin,是否修改请求地址的源
* 默认changeOrigin: false,即发请求即使用devServer的localhost:port发起的,如果后端服务器有校验源,就会有问题
* 设置changeOrigin: true,就会修改发起请求的源,将原本的localhost:port修改为target,这样就可以通过后端服务器对源的校验
*/
changeOrigin: true,
rewrite: (path) => path.replace(/^\/prodapi/, '/'),
},
},
},
};
});