perf: Improve the global loading display

This commit is contained in:
vben
2024-06-02 23:50:58 +08:00
parent e650a0b863
commit 77d40dc763
14 changed files with 111 additions and 57 deletions

View File

@@ -7,11 +7,11 @@ import { defineConfig, loadEnv, mergeConfig } from 'vite';
import { getApplicationConditionPlugins } from '../plugins';
import { getCommonConfig } from './common';
import type { DefineAppcationOptions } from '../typing';
import type { DefineApplicationOptions } from '../typing';
function defineApplicationConfig(options: DefineAppcationOptions = {}) {
function defineApplicationConfig(options: DefineApplicationOptions = {}) {
return defineConfig(async ({ command, mode }) => {
const { appcation = {}, vite = {} } = options;
const { application = {}, vite = {} } = options;
const root = process.cwd();
const isBuild = command === 'build';
const env = loadEnv(mode, root);
@@ -29,11 +29,10 @@ function defineApplicationConfig(options: DefineAppcationOptions = {}) {
mock: true,
mode,
turboConsole: false,
...appcation,
...application,
});
const applicationConfig: UserConfig = {
// },
build: {
rollupOptions: {
output: {
@@ -44,7 +43,6 @@ function defineApplicationConfig(options: DefineAppcationOptions = {}) {
},
target: 'es2015',
},
// },
esbuild: {
drop: isBuild
? [

View File

@@ -1,7 +1,6 @@
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import { fs } from '@vben/node-utils';
import { defineApplicationConfig } from './application';
import { defineLibraryConfig } from './library';
@@ -18,13 +17,19 @@ function defineConfig(options: DefineConfig = {}) {
// 根据包是否存在 index.html,自动判断类型
if (type === 'auto') {
const htmlPath = join(process.cwd(), 'index.html');
projectType = fs.existsSync(htmlPath) ? 'appcation' : 'library';
projectType = existsSync(htmlPath) ? 'application' : 'library';
}
if (projectType === 'appcation') {
return defineApplicationConfig(defineOptions);
} else if (projectType === 'library') {
return defineLibraryConfig(defineOptions);
switch (projectType) {
case 'application': {
return defineApplicationConfig(defineOptions);
}
case 'library': {
return defineLibraryConfig(defineOptions);
}
default: {
throw new Error(`Unsupported project type: ${projectType}`);
}
}
}

View File

@@ -33,7 +33,7 @@ function defineLibraryConfig(options: DefineLibraryOptions = {}) {
build: {
lib: {
entry: 'src/index.ts',
fileName: () => 'index.mjs',
fileName: 'index.mjs',
formats: ['es'],
},
rollupOptions: {