Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1c7e3e1

Browse filesBrowse files
committed
fix: reloading 问题
1 parent 1b6be1e commit 1c7e3e1
Copy full SHA for 1c7e3e1

File tree

Expand file treeCollapse file tree

2 files changed

+21
-7
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-7
lines changed

‎src/router/index.ts

Copy file name to clipboardExpand all lines: src/router/index.ts
+2-7Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,16 +404,11 @@ const createTheRouter = ():Router => createRouter({
404404
routes: constantRoutes
405405
});
406406

407-
interface RouterPro extends Router {
408-
matcher: unknown;
409-
}
410-
411-
const router = createTheRouter() as RouterPro;
407+
const router:Router = createTheRouter();
412408

413409
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
414410
export function resetRouter() {
415-
const newRouter = createTheRouter() as RouterPro;
416-
router.matcher = newRouter.matcher; // reset router
411+
router.clearRoutes();
417412
}
418413

419414
export default router;

‎vite.config.ts

Copy file name to clipboardExpand all lines: vite.config.ts
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { fileURLToPath, URL } from 'node:url';
22
import path from 'node:path';
3+
import fs from 'fs';
34

45
import { defineConfig, loadEnv } from 'vite';
56
import vue from '@vitejs/plugin-vue';
@@ -22,6 +23,21 @@ export default defineConfig(({ command, mode }) => {
2223
// According to the project configuration. Can be configured in the .env file
2324
const prodMock = true;
2425

26+
// 解决终端 optimized dependencies changed. reloading 问题
27+
const optimizeDepsElementPlusIncludes = ['element-plus/es'];
28+
fs.readdirSync('node_modules/element-plus/es/components').map((dirname) => {
29+
fs.access(
30+
`node_modules/element-plus/es/components/${dirname}/style/css.mjs`,
31+
(err) => {
32+
if (!err) {
33+
optimizeDepsElementPlusIncludes.push(
34+
`element-plus/es/components/${dirname}/style/css`
35+
);
36+
}
37+
}
38+
);
39+
});
40+
2541
return {
2642
base: '/', // 注意,必须以"/"结尾,BASE_URL配置
2743
define: {
@@ -33,6 +49,9 @@ export default defineConfig(({ command, mode }) => {
3349
},
3450
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
3551
},
52+
optimizeDeps: {
53+
include: optimizeDepsElementPlusIncludes
54+
},
3655
plugins: [
3756
vue(),
3857
Inspect(),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.