2022-08-16 15:30:23 +00:00
|
|
|
import { resolve } from 'path';
|
|
|
|
import { wrapperEnv } from './src/utils/get-env';
|
|
|
|
import { visualizer } from 'rollup-plugin-visualizer';
|
|
|
|
import viteCompression from 'vite-plugin-compression';
|
|
|
|
import VueSetupExtend from 'vite-plugin-vue-setup-extend';
|
|
|
|
import eslintPlugin from 'vite-plugin-eslint';
|
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
|
|
import DefineOptions from 'unplugin-vue-define-options/vite';
|
2024-07-02 06:38:04 +00:00
|
|
|
import { defineConfig, loadEnv, ConfigEnv, UserConfig } from 'vite';
|
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
|
|
import pkg from './package.json';
|
|
|
|
import dayjs from 'dayjs';
|
2022-08-16 15:30:23 +00:00
|
|
|
|
2023-01-12 03:45:01 +00:00
|
|
|
import AutoImport from 'unplugin-auto-import/vite';
|
|
|
|
import Components from 'unplugin-vue-components/vite';
|
|
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
|
2024-05-22 10:38:03 +00:00
|
|
|
import svgLoader from 'vite-svg-loader';
|
2023-01-12 03:45:01 +00:00
|
|
|
|
2023-03-16 09:24:25 +00:00
|
|
|
const prefix = `monaco-editor/esm/vs`;
|
|
|
|
|
2024-07-02 06:38:04 +00:00
|
|
|
const { dependencies, devDependencies, name, version } = pkg;
|
|
|
|
const __APP_INFO__ = {
|
|
|
|
pkg: { dependencies, devDependencies, name, version },
|
|
|
|
lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
};
|
|
|
|
|
2022-08-16 15:30:23 +00:00
|
|
|
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
|
|
|
const env = loadEnv(mode, process.cwd());
|
|
|
|
const viteEnv = wrapperEnv(env);
|
|
|
|
|
|
|
|
return {
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'@': resolve(__dirname, './src'),
|
|
|
|
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
|
2024-05-22 10:38:03 +00:00
|
|
|
xpack: resolve(__dirname, './src/xpack'),
|
2022-08-16 15:30:23 +00:00
|
|
|
},
|
|
|
|
},
|
2024-07-02 06:38:04 +00:00
|
|
|
define: {
|
|
|
|
__APP_INFO__: JSON.stringify(__APP_INFO__),
|
|
|
|
},
|
2022-08-16 15:30:23 +00:00
|
|
|
css: {
|
|
|
|
preprocessorOptions: {
|
|
|
|
scss: {
|
|
|
|
additionalData: `@use "@/styles/var.scss" as *;`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
server: {
|
|
|
|
port: viteEnv.VITE_PORT,
|
|
|
|
open: viteEnv.VITE_OPEN,
|
2023-04-08 06:04:11 +00:00
|
|
|
host: '0.0.0.0',
|
2022-08-16 15:30:23 +00:00
|
|
|
proxy: {
|
2024-07-25 06:43:41 +00:00
|
|
|
'/api/v2': {
|
2023-05-23 07:45:47 +00:00
|
|
|
target: 'http://localhost:9999/',
|
2022-08-16 15:30:23 +00:00
|
|
|
changeOrigin: true,
|
2023-04-05 14:02:19 +00:00
|
|
|
ws: true,
|
2022-08-16 15:30:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
vue(),
|
|
|
|
DefineOptions(),
|
2022-08-19 08:02:58 +00:00
|
|
|
eslintPlugin({
|
|
|
|
exclude: ['**/*.js'],
|
|
|
|
}),
|
2022-08-16 15:30:23 +00:00
|
|
|
vueJsx(),
|
|
|
|
VueSetupExtend(),
|
|
|
|
viteEnv.VITE_REPORT && visualizer(),
|
|
|
|
viteEnv.VITE_BUILD_GZIP &&
|
|
|
|
viteCompression({
|
|
|
|
verbose: true,
|
|
|
|
disable: false,
|
|
|
|
threshold: 10240,
|
|
|
|
algorithm: 'gzip',
|
|
|
|
ext: '.gz',
|
|
|
|
}),
|
2023-01-12 03:45:01 +00:00
|
|
|
AutoImport({
|
2024-07-02 06:38:04 +00:00
|
|
|
imports: ['vue', 'vue-router'],
|
2023-01-12 03:45:01 +00:00
|
|
|
resolvers: [
|
|
|
|
ElementPlusResolver({
|
|
|
|
importStyle: 'sass',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
Components({
|
|
|
|
resolvers: [
|
|
|
|
ElementPlusResolver({
|
|
|
|
importStyle: 'sass',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
2024-05-22 10:38:03 +00:00
|
|
|
svgLoader({
|
|
|
|
defaultImport: 'url',
|
|
|
|
}),
|
2022-08-16 15:30:23 +00:00
|
|
|
],
|
|
|
|
esbuild: {
|
|
|
|
pure: viteEnv.VITE_DROP_CONSOLE ? ['console.log', 'debugger'] : [],
|
|
|
|
},
|
|
|
|
build: {
|
2022-10-17 08:32:31 +00:00
|
|
|
outDir: '../cmd/server/web',
|
2022-08-16 15:30:23 +00:00
|
|
|
minify: 'esbuild',
|
2024-03-27 10:26:07 +00:00
|
|
|
target: 'esnext',
|
2022-08-16 15:30:23 +00:00
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
|
|
|
chunkFileNames: 'assets/js/[name]-[hash].js',
|
|
|
|
entryFileNames: 'assets/js/[name]-[hash].js',
|
|
|
|
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
|
2023-03-16 09:24:25 +00:00
|
|
|
manualChunks: {
|
|
|
|
jsonWorker: [`${prefix}/language/json/json.worker`],
|
|
|
|
cssWorker: [`${prefix}/language/css/css.worker`],
|
|
|
|
htmlWorker: [`${prefix}/language/html/html.worker`],
|
|
|
|
tsWorker: [`${prefix}/language/typescript/ts.worker`],
|
|
|
|
editorWorker: [`${prefix}/editor/editor.worker`],
|
|
|
|
},
|
2022-08-16 15:30:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|