Skip to content

Commit 40b2ce6

Browse files
committed
perf: optimize for some details and comments
1 parent d3ed675 commit 40b2ce6

File tree

17 files changed

+31
-130
lines changed

17 files changed

+31
-130
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
push:
66
branches:
77
- main
8-
- master
98
- "releases/*"
109

1110
permissions:
@@ -25,8 +24,8 @@ jobs:
2524
node-version: [20]
2625
os:
2726
- ubuntu-latest
28-
# - macos-latest
29-
# - windows-latest
27+
- macos-latest
28+
- windows-latest
3029
timeout-minutes: 20
3130
steps:
3231
- name: Checkout code

.github/workflows/semantic-pull-request.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99

1010
jobs:
1111
main:
12-
if: github.repository == 'vitejs/vite'
1312
runs-on: ubuntu-latest
1413
name: Semantic Pull Request
1514
steps:

deploy/nginx.conf

Lines changed: 0 additions & 87 deletions
This file was deleted.

docs/src/guide/in-depth/loading.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## 原理
88

9-
`vite-plugin-inject-app-loading` 插件实现,插件会在每个页面的注入一个全局的 loading html。
9+
`vite-plugin-inject-app-loading` 插件实现,插件会在每个应用的注入一个全局的 `loading html`
1010

1111
## 关闭
1212

internal/vite-config/src/config/application.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { getCommonConfig } from './common';
1515

1616
function defineApplicationConfig(userConfigPromise?: DefineApplicationOptions) {
1717
return defineConfig(async (config) => {
18-
const { appTitle, base, port, ...envConfig } = await loadAndConvertEnv();
1918
const options = await userConfigPromise?.(config);
19+
const { appTitle, base, port, ...envConfig } = await loadAndConvertEnv();
2020
const { command, mode } = config;
2121
const { application = {}, vite = {} } = options || {};
2222
const root = process.cwd();
@@ -78,16 +78,16 @@ function defineApplicationConfig(userConfigPromise?: DefineApplicationOptions) {
7878
port,
7979
warmup: {
8080
// 预热文件
81-
clientFiles: ['./index.html', './src/{views,layouts}/*'],
81+
clientFiles: ['./index.html', './src/{views,layouts,router,store}/*'],
8282
},
8383
},
8484
};
8585

86-
const mergedConfig = mergeConfig(
86+
const mergedCommonConfig = mergeConfig(
8787
await getCommonConfig(),
8888
applicationConfig,
8989
);
90-
return mergeConfig(mergedConfig, vite);
90+
return mergeConfig(mergedCommonConfig, vite);
9191
});
9292
}
9393

internal/vite-config/src/config/library.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function defineLibraryConfig(userConfigPromise?: DefineLibraryOptions) {
1313
return defineConfig(async (config: ConfigEnv) => {
1414
const options = await userConfigPromise?.(config);
1515
const { command, mode } = config;
16-
const root = process.cwd();
1716
const { library = {}, vite = {} } = options || {};
17+
const root = process.cwd();
1818
const isBuild = command === 'build';
1919

2020
const plugins = await loadLibraryPlugins({
@@ -52,8 +52,8 @@ function defineLibraryConfig(userConfigPromise?: DefineLibraryOptions) {
5252
plugins,
5353
};
5454
const commonConfig = await getCommonConfig();
55-
const mergedConfig = mergeConfig(commonConfig, packageConfig);
56-
return mergeConfig(mergedConfig, vite);
55+
const mergedConmonConfig = mergeConfig(commonConfig, packageConfig);
56+
return mergeConfig(mergedConmonConfig, vite);
5757
});
5858
}
5959

internal/vite-config/src/options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ const getDefaultPwaOptions = (name: string): Partial<PwaPluginOptions> => ({
2828
const defaultImportmapOptions: ImportmapPluginOptions = {
2929
// 通过 Importmap CDN 方式引入,
3030
// 目前只有esm.sh源兼容性好一点,jspm.io对于 esm 入口要求高
31-
defaultProvider: 'jspm.io',
31+
defaultProvider: 'esm.sh',
3232
importmap: [
3333
{ name: 'vue' },
3434
{ name: 'pinia' },
3535
{ name: 'vue-router' },
36-
{ name: 'vue-i18n' },
36+
// { name: 'vue-i18n' },
3737
{ name: 'dayjs' },
3838
{ name: 'vue-demi' },
3939
],
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# inject-app-loading
22

3-
用于在应用加载时显示加载动画的插件可自行选择加载动画的样式。
3+
用于在应用加载时显示加载动画的插件可自行选择加载动画的样式。

internal/vite-config/src/plugins/inject-app-loading/default-loading.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
pointer-events: none;
2626
visibility: hidden;
2727
opacity: 0;
28-
transition: all 0.6s ease-out;
28+
transition: all 1s ease-out;
2929
}
3030

3131
.dark .loading {

internal/vite-config/src/plugins/inject-app-loading/index.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,15 @@ async function viteInjectAppLoadingPlugin(
5252
* 用于获取loading的html模板
5353
*/
5454
async function getLoadingRawByHtmlTemplate(loadingTemplate: string) {
55-
const __dirname = fileURLToPath(new URL('.', import.meta.url));
56-
const defaultLoadingPath = join(__dirname, './default-loading.html');
5755
// 支持在app内自定义loading模板,模版参考default-loading.html即可
58-
const appLoadingPath = join(process.cwd(), loadingTemplate);
59-
let loadingPath = defaultLoadingPath;
56+
let appLoadingPath = join(process.cwd(), loadingTemplate);
6057

61-
if (fs.existsSync(appLoadingPath)) {
62-
loadingPath = appLoadingPath;
63-
return;
58+
if (!fs.existsSync(appLoadingPath)) {
59+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
60+
appLoadingPath = join(__dirname, './default-loading.html');
6461
}
6562

66-
const htmlRaw = await fsp.readFile(loadingPath, 'utf8');
67-
return htmlRaw;
63+
return await fsp.readFile(appLoadingPath, 'utf8');
6864
}
6965

7066
export { viteInjectAppLoadingPlugin };

internal/vite-config/src/typing.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ interface CommonPluginOptions {
7474
}
7575

7676
interface ApplicationPluginOptions extends CommonPluginOptions {
77-
/** 开启 gzip 压缩 */
77+
/** 开启 gzip|brotli 压缩 */
7878
compress?: boolean;
7979
/** 压缩类型 */
8080
compressTypes?: ('brotli' | 'gzip')[];
8181
/** 在构建的时候抽离配置文件 */
8282
extraAppConfig?: boolean;
83-
/** html 插件配置 */
83+
/** 是否开启html插件 */
8484
html?: boolean;
8585
/** 是否开启i18n */
8686
i18n?: boolean;
@@ -98,7 +98,7 @@ interface ApplicationPluginOptions extends CommonPluginOptions {
9898
nitroMock?: boolean;
9999
/** nitro mock 插件配置 */
100100
nitroMockOptions?: NitroMockPluginOptions;
101-
/** dev是否开启mock服务 */
101+
/** 开启控制台自定义打印 */
102102
print?: boolean;
103103
/** 打印插件配置 */
104104
printInfoMap?: PrintPluginOptions['infoMap'];

packages/@core/preferences/src/preferences.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ const STORAGE_KEY = 'preferences';
1919
const STORAGE_KEY_LOCALE = `${STORAGE_KEY}-locale`;
2020
const STORAGE_KEY_THEME = `${STORAGE_KEY}-theme`;
2121

22-
function isDarkTheme(theme: string) {
23-
let dark = theme === 'dark';
24-
if (theme === 'auto') {
25-
dark = window.matchMedia('(prefers-color-scheme: dark)').matches;
26-
}
27-
return dark;
28-
}
29-
3022
class PreferenceManager {
3123
private cache: null | StorageManager = null;
3224
// private flattenedState: Flatten<Preferences>;
@@ -39,6 +31,7 @@ class PreferenceManager {
3931
constructor() {
4032
this.cache = new StorageManager();
4133

34+
// 避免频繁的操作缓存
4235
this.savePreferences = useDebounceFn(
4336
(preference: Preferences) => this._savePreferences(preference),
4437
150,
@@ -58,7 +51,6 @@ class PreferenceManager {
5851
/**
5952
* 处理更新的键值
6053
* 根据更新的键值执行相应的操作。
61-
*
6254
* @param {DeepPartial<Preferences>} updates - 部分更新的偏好设置
6355
*/
6456
private handleUpdates(updates: DeepPartial<Preferences>) {
@@ -124,7 +116,7 @@ class PreferenceManager {
124116
this.updatePreferences({
125117
theme: { mode: isDark ? 'dark' : 'light' },
126118
});
127-
updateCSSVariables(this.state);
119+
// updateCSSVariables(this.state);
128120
});
129121
}
130122

@@ -232,4 +224,4 @@ class PreferenceManager {
232224
}
233225

234226
const preferencesManager = new PreferenceManager();
235-
export { isDarkTheme, PreferenceManager, preferencesManager };
227+
export { PreferenceManager, preferencesManager };

packages/@core/preferences/src/update-css-variables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@ function isDarkTheme(theme: string) {
115115
return dark;
116116
}
117117

118-
export { updateCSSVariables };
118+
export { isDarkTheme, updateCSSVariables };

packages/@core/preferences/src/use-preferences.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { computed } from 'vue';
22

33
import { diff } from '@vben-core/shared';
44

5-
import { isDarkTheme, preferencesManager } from './preferences';
5+
import { preferencesManager } from './preferences';
6+
import { isDarkTheme } from './update-css-variables';
67

78
function usePreferences() {
89
const preferences = preferencesManager.getPreferences();

packages/effects/hooks/src/use-design-tokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export function useElementPlusDesignTokens() {
209209
'--el-text-color-primary': getCssVariableValue('--foreground'),
210210
'--el-text-color-regular': getCssVariableValue('--foreground'),
211211
};
212-
updateCSSVariables(variables, `__vben_ele_styles__`);
212+
updateCSSVariables(variables, `__vben_design_styles__`);
213213
},
214214
{ immediate: true },
215215
);

packages/utils/src/helpers/unmount-global-loading.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* 放在这里是而不是放在 index.html 的app标签内,是因为这样比较不会生硬,渲染过快可能会有闪烁
44
* 通过先添加css动画隐藏,在动画结束后在移除loading节点来改善体验
55
* 不好的地方是会增加一些代码量
6+
* 自定义loading可以见:https://doc.vben.pro/guide/in-depth/loading.html
67
*/
78
export function unmountGlobalLoading() {
89
// 查找全局 loading 元素

scripts/turbo-run/src/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function run(options: RunOptions) {
2020

2121
// 只显示有对应命令的包
2222
const selectPkgs = packages.filter((pkg) => {
23-
return (pkg?.packageJson as Record<string, any>).scripts?.[command];
23+
return (pkg?.packageJson as Record<string, any>)?.scripts?.[command];
2424
});
2525

2626
const selectPkg = await select<any, string>({

0 commit comments

Comments
 (0)