137 lines
3.7 KiB
TypeScript
137 lines
3.7 KiB
TypeScript
import { resolve } from 'node:path';
|
||
import { loadEnv } from 'vite';
|
||
import vueJsx from '@vitejs/plugin-vue-jsx';
|
||
import mkcert from 'vite-plugin-mkcert';
|
||
import vue from '@vitejs/plugin-vue';
|
||
import checker from 'vite-plugin-checker';
|
||
import Components from 'unplugin-vue-components/vite';
|
||
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
|
||
import Unocss from 'unocss/vite';
|
||
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
|
||
import dayjs from 'dayjs';
|
||
import Http2Proxy from '@sy/vite-plugin-http2-proxy';
|
||
import Inspector from 'vite-plugin-vue-inspector';
|
||
import pkg from './package.json';
|
||
import type { UserConfig, ConfigEnv } from 'vite';
|
||
// import { DEV_SERVER_PORT } from '@sy/low-code-shared/dist/constants';
|
||
|
||
// console.log(DEV_SERVER_PORT);
|
||
|
||
const __APP_INFO__ = {
|
||
pkg,
|
||
lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||
};
|
||
|
||
// https://vitejs.dev/config/
|
||
export default ({ command, mode }: ConfigEnv): UserConfig => {
|
||
console.log('mode', mode);
|
||
// 环境变量
|
||
const env = loadEnv(mode, process.cwd(), ['VITE_', 'VTJ_', 'SY_', 'Y_CODE_']);
|
||
console.log('env', env);
|
||
const isDev = command === 'serve';
|
||
|
||
return {
|
||
define: {
|
||
__APP_INFO__: JSON.stringify(__APP_INFO__),
|
||
// 注入环境变量到客户端
|
||
__APP_ENV__: JSON.stringify(env),
|
||
},
|
||
resolve: {
|
||
alias: [
|
||
{
|
||
find: '@',
|
||
replacement: resolve(__dirname, './src'),
|
||
},
|
||
],
|
||
},
|
||
server: {
|
||
open: true,
|
||
host: true,
|
||
cors: true,
|
||
port: Number(env.VITE_PORT),
|
||
proxy: {
|
||
'/api': {
|
||
target: 'https://custom-chart-pre-api.shiyue.com',
|
||
changeOrigin: true,
|
||
secure: false,
|
||
},
|
||
},
|
||
},
|
||
plugins: [
|
||
vue(),
|
||
Inspector(),
|
||
Unocss(),
|
||
vueJsx(),
|
||
// 指定 mkcert 的下载源为 coding,从 coding.net 镜像下载证书
|
||
mkcert({ source: 'coding' }),
|
||
// 开启 http2 代理
|
||
Http2Proxy(),
|
||
createSvgIconsPlugin({
|
||
// Specify the icon folder to be cached
|
||
iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
|
||
// Specify symbolId format
|
||
symbolId: 'svg-icon-[dir]-[name]',
|
||
}),
|
||
Components({
|
||
dts: 'types/components.d.ts',
|
||
types: [
|
||
{
|
||
from: './src/components/basic/button/',
|
||
names: ['AButton'],
|
||
},
|
||
{
|
||
from: 'vue-router',
|
||
names: ['RouterLink', 'RouterView'],
|
||
},
|
||
],
|
||
resolvers: [
|
||
AntDesignVueResolver({
|
||
importStyle: false, // css in js
|
||
exclude: ['Button'],
|
||
}),
|
||
],
|
||
}),
|
||
// https://github.com/fi3ework/vite-plugin-checker
|
||
isDev &&
|
||
checker({
|
||
typescript: true,
|
||
// vueTsc: true,
|
||
eslint: {
|
||
useFlatConfig: true,
|
||
lintCommand: 'eslint "./src/**/*.{.vue,ts,tsx}"', // for example, lint .ts & .tsx
|
||
},
|
||
overlay: {
|
||
initialIsOpen: false,
|
||
},
|
||
}),
|
||
],
|
||
css: {
|
||
preprocessorOptions: {
|
||
less: {
|
||
javascriptEnabled: true,
|
||
modifyVars: {},
|
||
},
|
||
},
|
||
},
|
||
optimizeDeps: {
|
||
include: ['lodash-es', 'ant-design-vue/es/locale/zh_CN', 'ant-design-vue/es/locale/en_US'],
|
||
},
|
||
esbuild: {
|
||
supported: {
|
||
// https://github.com/vitejs/vite/pull/8665
|
||
'top-level-await': true,
|
||
},
|
||
},
|
||
build: {
|
||
// outDir: resolve(process.cwd(), '../../dist/platform'), // 输出到根目录/designer
|
||
emptyOutDir: true,
|
||
terserOptions: {
|
||
compress: {
|
||
drop_console: true,
|
||
drop_debugger: true,
|
||
},
|
||
},
|
||
},
|
||
};
|
||
};
|