123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- import type { UserConfig, ConfigEnv } from 'vite';
- import pkg from './package.json';
- import dayjs from 'dayjs';
- import { loadEnv } from 'vite';
- import { resolve } from 'path';
- import { generateModifyVars } from './build/generate/generateModifyVars';
- import { createProxy } from './build/vite/proxy';
- import { wrapperEnv } from './build/utils';
- import { createVitePlugins } from './build/vite/plugin';
- import { OUTPUT_DIR } from './build/constant';
- import { include, exclude } from './build/vite/optimize';
- function pathResolve(dir: string) {
- return resolve(process.cwd(), '.', dir);
- }
- const { dependencies, devDependencies, name, version } = pkg;
- const __APP_INFO__ = {
- pkg: { dependencies, devDependencies, name, version },
- lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
- };
- export default ({ command, mode }: ConfigEnv): UserConfig => {
- const root = process.cwd();
- const env = loadEnv(mode, root);
-
- const viteEnv = wrapperEnv(env);
- const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE } = viteEnv;
- const isBuild = command === 'build';
- return {
- base: VITE_PUBLIC_PATH,
- root,
- server: {
- https: false,
-
- host: true,
- port: VITE_PORT,
-
- proxy: createProxy(VITE_PROXY),
- },
- resolve: {
- alias: [
- {
- find: 'vue-i18n',
- replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
- },
-
- {
- find: /\/@\//,
- replacement: pathResolve('src') + '/',
- },
- {
- find: /\/@bpmn\//,
- replacement: pathResolve('src') + '/views/workflow/design/bpmn/',
- },
-
- {
- find: /\/#\//,
- replacement: pathResolve('types') + '/',
- },
- ],
- },
- esbuild: {
- drop: VITE_DROP_CONSOLE ? ['console', 'debugger'] : [],
- },
- build: {
- target: 'es2015',
- cssTarget: 'chrome80',
- outDir: OUTPUT_DIR,
-
-
-
-
-
-
-
-
-
- reportCompressedSize: false,
- chunkSizeWarningLimit: 2000,
- },
- define: {
- __APP_INFO__: JSON.stringify(__APP_INFO__),
- },
- css: {
- preprocessorOptions: {
- less: {
- modifyVars: generateModifyVars(),
- javascriptEnabled: true,
- },
- },
- },
-
- plugins: createVitePlugins(viteEnv, isBuild),
- optimizeDeps: { include, exclude },
- };
- };
|