Skip to content

Commit bdb059b

Browse files
committed
feat: support window.GLOBAL_CONFIG
1 parent 15a7104 commit bdb059b

38 files changed

+2395
-113
lines changed

.env.development

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ VITE_BASE_PATH = /
44

55
VITE_DROP_CONSOLE = false
66

7-
VITE_BASE_SERVER = http://192.168.1.39:5888
7+
VITE_BASE_SERVER = http://127.0.0.1
88

9-
VITE_RESOURCE_SERVER = http://192.168.1.39:7800
9+
VITE_RESOURCE_SERVER = http://127.0.0.1

.env.production

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,3 @@ VITE_USE_MOCK = true
33
VITE_BASE_PATH = /
44

55
VITE_DROP_CONSOLE = true
6-
7-
VITE_BASE_SERVER = http://www.cnqisoft.com:5918
8-
9-
VITE_RESOURCE_SERVER = http://www.cnqisoft.com:5917

.eslintcache

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

build/plugins/icon.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { relative } from 'node:path'
22
import { readFileSync } from 'node:fs'
3+
34
import glob from 'fast-glob'
45
import { normalizePath } from 'vite'
56

@@ -101,13 +102,14 @@ export function createIconPlugin(options: IconPluginOptions = {}): Plugin {
101102
isBuild = config.command === 'build'
102103
},
103104
resolveId(id) {
104-
return ICON_REGISTER === id ? id : null
105+
return ICON_REGISTER === id ? `\0${id}` : null
105106
},
106107
async load(id, ssr) {
107-
if (!isBuild || ICON_REGISTER !== id) return null
108-
if (ssr && !isBuild) return 'export default {}'
108+
if (!isBuild && !ssr) return null
109109

110-
return await renderModuleCode()
110+
if (id.endsWith(ICON_REGISTER)) {
111+
return ssr && !isBuild ? 'export default {}' : await renderModuleCode()
112+
}
111113
},
112114
configureServer: ({ middlewares }) => {
113115
// middlewares.use(cors({ origin: '*' }))

build/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { resolve } from 'node:path'
22
import { fileURLToPath } from 'node:url'
3-
import { bgYellow, bgCyan, bgGreen, bgRed, yellow, cyan, green, red } from 'kolorist'
3+
4+
import { bgCyan, bgGreen, bgRed, bgYellow, cyan, green, red, yellow } from 'kolorist'
45

56
import type { Config } from 'prettier'
67

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
</head>
1010
<body>
1111
<div id="app"></div>
12+
<script src="/global-config.js"></script>
13+
<script>
14+
if (!window.GLOBAL_CONFIG) window.GLOBAL_CONFIG = {}
15+
</script>
1216
<script type="module" src="/src/main.ts"></script>
1317
</body>
1418
</html>

mock/article.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Random } from 'mockjs'
2-
import { mockCommonRequests, createBusinessBase } from './common'
2+
import { createBusinessBase, mockCommonRequests } from './common'
33

44
import type { Article } from '@/service/article'
55

6-
const richText = '<p>Some content for testing.</p><p><img src="https://www.vexipui.com/picture-4.jpg" alt="" data-href="" style="width: 610.00px;height: 381.25px;"/></p><p>Some content for testing.</p>'
6+
const richText =
7+
'<p>Some content for testing.</p><p><img src="https://www.vexipui.com/picture-4.jpg" alt="" data-href="" style="width: 610.00px;height: 381.25px;"/></p><p>Some content for testing.</p>'
78

89
mockCommonRequests('/api/article', (): Article[] => {
910
return Array.from({ length: 20 }, (_, index) => {
@@ -14,9 +15,11 @@ mockCommonRequests('/api/article', (): Article[] => {
1415
author: Random.first(),
1516
date: Random.datetime(),
1617
summary: Random.sentence(5, 15),
17-
cover: [{
18-
url: 'https://www.vexipui.com/picture-1.jpg'
19-
}],
18+
cover: [
19+
{
20+
url: 'https://www.vexipui.com/picture-1.jpg'
21+
}
22+
],
2023
content: richText
2124
}
2225
})

mock/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Mock, { mock, Random } from 'mockjs'
1+
import Mock, { Random, mock } from 'mockjs'
22
import { getUsers } from './user'
33

44
import type { Result } from '@/service/common'

mock/resource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mock, Random } from 'mockjs'
1+
import { Random, mock } from 'mockjs'
22

33
mock('/resource/file', async ({ body }) => {
44
if (body instanceof FormData) {

mock/user.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mock } from 'mockjs'
22

3-
import type { User, LoginParams } from '@/service/user'
3+
import type { LoginParams, User } from '@/service/user'
44
import type { MockParams } from './common'
55

66
export function getUsers(): Array<User & { password: string, token: string }> {
@@ -14,9 +14,7 @@ export function getUsers(): Array<User & { password: string, token: string }> {
1414
avatar: '',
1515
1616
lastLogin: Date.now(),
17-
roles: [
18-
{ name: 'Admin', auth: 'admin' }
19-
]
17+
roles: [{ name: 'Admin', auth: 'admin' }]
2018
},
2119
{
2220
id: '2',
@@ -27,9 +25,7 @@ export function getUsers(): Array<User & { password: string, token: string }> {
2725
avatar: 'https://www.vexipui.com/qmhc.jpg',
2826
2927
lastLogin: '2022-06-14T07:54:03.880+00:00',
30-
roles: [
31-
{ name: 'Guest', auth: 'guest' }
32-
]
28+
roles: [{ name: 'Guest', auth: 'guest' }]
3329
}
3430
]
3531
}

0 commit comments

Comments
 (0)