forked from cossteam/cossim-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
147 lines (138 loc) · 4.29 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
/*eslint no-undef: "off"*/
import path from 'path'
import react from '@vitejs/plugin-react'
import { defineConfig, loadEnv } from 'vite'
import { createHtmlPlugin } from 'vite-plugin-html'
// import electron from 'vite-plugin-electron/simple'
// import { VitePluginNode } from 'vite-plugin-node'
// import { nodePolyfills } from 'vite-plugin-node-polyfills'
// import requireTransform from 'vite-plugin-require-transform'
// import commonjs from '@rollup/plugin-commonjs'
// import Components from 'unplugin-vue-components/vite'
// import { VantResolver } from '@vant/auto-import-resolver'
// import babel from 'vite-plugin-babel'
// import babelConfig from './babel.config'
process.env.TARGET = process.env.TARGET || 'web'
const isCordova = process.env.TARGET === 'cordova'
const SRC_DIR = path.resolve(__dirname, './src')
const PUBLIC_DIR = path.resolve(__dirname, './public')
const BUILD_DIR = path.resolve(__dirname, isCordova ? './cordova/www' : './www')
import mkcert from 'vite-plugin-mkcert'
/*** @type {import('vite').UserConfig} */
export default async ({ mode }) => {
const http = loadEnv(mode, process.cwd())
console.log('http', http, mode)
return defineConfig({
plugins: [
react(),
createHtmlPlugin({
minify: false,
inject: {
data: {
TARGET: process.env.TARGET
}
}
}),
mkcert()
// babel()
// Components({
// resolvers: [VantResolver()]
// })
// commonjs()
// requireTransform({
// fileRegex: /.js$|.vue$|.ts$|.tsx$|.jsx$/
// })
// electron({
// main: {
// // Shortcut of `build.lib.entry`.
// entry: 'electron/main.js'
// },
// preload: {
// // Shortcut of `build.rollupOptions.input`.
// // Preload scripts may contain Web assets, so use the `build.rollupOptions.input` instead `build.lib.entry`.
// input: path.join(__dirname, 'electron/preload.js')
// },
// // Ployfill the Electron and Node.js built-in modules for Renderer process.
// // See 👉 https://github.com/electron-vite/vite-plugin-electron-renderer
// renderer: {}
// })
// nodePolyfills({
// include:['fs','path'],
// globals: {
// Buffer: true,
// global: true,
// process: true,
// }
// }),
// ...VitePluginNode({
// // Nodejs 原生请求适配器
// // 目前这个插件支持'express','nest','koa'和'fastify'开箱即用,
// // 如果您使用其他框架,您还可以传递函数,请参阅自定义适配器部分
// adapter: 'express',
// // 告诉插件你的项目入口在哪里
// appPath: './src/main.js',
// // 可选,默认:'viteNodeApp'
// // appPath 文件中您的应用程序的命名导出的名称
// // exportName: 'viteNodeApp',
// // 可选,默认: false
// // 如果您想在启动时初始化您的应用程序,请将其设置为 true
// // initAppOnBoot: false,
// // Optional, default: 'esbuild'
// // The TypeScript compiler you want to use
// // by default this plugin is using vite default ts compiler which is esbuild
// // 'swc' compiler is supported to use as well for frameworks
// // like Nestjs (esbuild dont support 'emitDecoratorMetadata' yet)
// // you need to INSTALL `@swc/core` as dev dependency if you want to use swc
// // tsCompiler: 'esbuild',
// // Optional, default: {
// // jsc: {
// // target: 'es2019',
// // parser: {
// // syntax: 'typescript',
// // decorators: true
// // },
// // transform: {
// // legacyDecorator: true,
// // decoratorMetadata: true
// // }
// // }
// // }
// // swc configs, see [swc doc](https://swc.rs/docs/configuration/swcrc)
// // swcOptions: {}
// })
],
root: SRC_DIR,
base: '',
publicDir: PUBLIC_DIR,
build: {
// target: 'ES2022',
outDir: BUILD_DIR,
assetsInlineLimit: 0,
emptyOutDir: true,
rollupOptions: {
treeshake: false
},
// 设置 externals,避免打包时将 Node.js 模块打包进去
external: ['electron']
},
resolve: {
alias: {
'@': SRC_DIR
}
},
server: {
https: true,
proxy: {
'/api/v1': {
target: 'https://coss.gezi.vip',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api\/v1/, '')
}
}
},
define: {
// 'process': true
'process.env': {}
}
})
}