@gx-design-vue/create-gx-cli 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. package/bin/create-gx-cli +3 -2
  2. package/package.json +4 -4
  3. package/src/cli.js +10 -7
  4. package/src/git.js +8 -5
  5. package/src/main.js +29 -16
  6. package/template-mobile-vant-cli/package.json +5 -5
  7. package/template-gx-design-thin/.editorconfig +0 -19
  8. package/template-gx-design-thin/.env +0 -4
  9. package/template-gx-design-thin/.env.development +0 -15
  10. package/template-gx-design-thin/.env.production +0 -28
  11. package/template-gx-design-thin/.eslintignore +0 -16
  12. package/template-gx-design-thin/.prettierignore +0 -9
  13. package/template-gx-design-thin/LICENSE +0 -21
  14. package/template-gx-design-thin/README.md +0 -112
  15. package/template-gx-design-thin/build/constant.ts +0 -1
  16. package/template-gx-design-thin/build/generate/generateModifyVars.ts +0 -14
  17. package/template-gx-design-thin/build/rollupOptions/index.ts +0 -22
  18. package/template-gx-design-thin/build/util/hash.ts +0 -17
  19. package/template-gx-design-thin/build/util/index.ts +0 -131
  20. package/template-gx-design-thin/build/vite/cdn.ts +0 -63
  21. package/template-gx-design-thin/build/vite/optimizer.ts +0 -26
  22. package/template-gx-design-thin/build/vite/plugin/appConfig.ts +0 -91
  23. package/template-gx-design-thin/build/vite/plugin/autoImport.ts +0 -26
  24. package/template-gx-design-thin/build/vite/plugin/compress.ts +0 -31
  25. package/template-gx-design-thin/build/vite/plugin/html.ts +0 -39
  26. package/template-gx-design-thin/build/vite/plugin/index.ts +0 -75
  27. package/template-gx-design-thin/build/vite/plugin/mock.ts +0 -14
  28. package/template-gx-design-thin/build/vite/plugin/pwa.ts +0 -31
  29. package/template-gx-design-thin/build/vite/plugin/visualizer.ts +0 -14
  30. package/template-gx-design-thin/build/vite/plugin/viteMock/client.ts +0 -88
  31. package/template-gx-design-thin/build/vite/plugin/viteMock/createMockServer.ts +0 -271
  32. package/template-gx-design-thin/build/vite/plugin/viteMock/index.ts +0 -69
  33. package/template-gx-design-thin/build/vite/plugin/viteMock/types.ts +0 -48
  34. package/template-gx-design-thin/build/vite/plugin/viteMock/utils.ts +0 -48
  35. package/template-gx-design-thin/build/vite/plugin/viteNotice.ts +0 -40
  36. package/template-gx-design-thin/commitlint.config.cjs +0 -32
  37. package/template-gx-design-thin/config/default/defaultSettings.ts +0 -78
  38. package/template-gx-design-thin/config/default/network.ts +0 -10
  39. package/template-gx-design-thin/config/default/proxy.ts +0 -47
  40. package/template-gx-design-thin/config/default/theme.ts +0 -3
  41. package/template-gx-design-thin/config/index.ts +0 -11
  42. package/template-gx-design-thin/eslint.config.js +0 -51
  43. package/template-gx-design-thin/index.html +0 -42
  44. package/template-gx-design-thin/mock/_createProductionServer.ts +0 -19
  45. package/template-gx-design-thin/mock/_util.ts +0 -33
  46. package/template-gx-design-thin/mock/config/menu.ts +0 -21
  47. package/template-gx-design-thin/mock/config/user.ts +0 -123
  48. package/template-gx-design-thin/mock/datasSource/system/menu.ts +0 -10
  49. package/template-gx-design-thin/mock/datasSource/user/account.ts +0 -30
  50. package/template-gx-design-thin/mock/datasSource/user/index.ts +0 -47
  51. package/template-gx-design-thin/mock/util/crypto.ts +0 -23
  52. package/template-gx-design-thin/mock/util/table.ts +0 -92
  53. package/template-gx-design-thin/mock/util/utils.ts +0 -73
  54. package/template-gx-design-thin/package.json +0 -129
  55. package/template-gx-design-thin/pnpm-lock.yaml +0 -12575
  56. package/template-gx-design-thin/prettier.config.cjs +0 -18
  57. package/template-gx-design-thin/public/resource/css/index.css +0 -119
  58. package/template-gx-design-thin/public/resource/css/normalize.css +0 -396
  59. package/template-gx-design-thin/public/resource/img/favicon.ico +0 -0
  60. package/template-gx-design-thin/public/resource/img/logo.png +0 -0
  61. package/template-gx-design-thin/public/resource/img/pro_icon.svg +0 -1
  62. package/template-gx-design-thin/public/resource/img/pwa-192x192.png +0 -0
  63. package/template-gx-design-thin/public/resource/img/pwa-512x512.png +0 -0
  64. package/template-gx-design-thin/src/App.vue +0 -42
  65. package/template-gx-design-thin/src/assets/error_images/403.png +0 -0
  66. package/template-gx-design-thin/src/assets/error_images/404.png +0 -0
  67. package/template-gx-design-thin/src/assets/error_images/cloud.png +0 -0
  68. package/template-gx-design-thin/src/assets/login_images/login_background.svg +0 -1
  69. package/template-gx-design-thin/src/assets/logo.png +0 -0
  70. package/template-gx-design-thin/src/assets/menu_font/iconfont.css +0 -94
  71. package/template-gx-design-thin/src/assets/menu_font/iconfont.eot +0 -0
  72. package/template-gx-design-thin/src/assets/menu_font/iconfont.js +0 -1
  73. package/template-gx-design-thin/src/assets/menu_font/iconfont.json +0 -142
  74. package/template-gx-design-thin/src/assets/menu_font/iconfont.svg +0 -1
  75. package/template-gx-design-thin/src/assets/menu_font/iconfont.ttf +0 -0
  76. package/template-gx-design-thin/src/assets/menu_font/iconfont.woff +0 -0
  77. package/template-gx-design-thin/src/assets/menu_font/iconfont.woff2 +0 -0
  78. package/template-gx-design-thin/src/assets/menu_font/index.less +0 -94
  79. package/template-gx-design-thin/src/assets/public_icon/iconfont.css +0 -42
  80. package/template-gx-design-thin/src/assets/public_icon/iconfont.eot +0 -0
  81. package/template-gx-design-thin/src/assets/public_icon/iconfont.js +0 -1
  82. package/template-gx-design-thin/src/assets/public_icon/iconfont.json +0 -51
  83. package/template-gx-design-thin/src/assets/public_icon/iconfont.svg +0 -1
  84. package/template-gx-design-thin/src/assets/public_icon/iconfont.ttf +0 -0
  85. package/template-gx-design-thin/src/assets/public_icon/iconfont.woff +0 -0
  86. package/template-gx-design-thin/src/assets/public_icon/iconfont.woff2 +0 -0
  87. package/template-gx-design-thin/src/assets/public_icon/index.less +0 -42
  88. package/template-gx-design-thin/src/assets/public_images/nodata.svg +0 -1
  89. package/template-gx-design-thin/src/common/global.ts +0 -4
  90. package/template-gx-design-thin/src/components/GDesign/Result/index.tsx +0 -144
  91. package/template-gx-design-thin/src/components/GDesign/Result/style.less +0 -140
  92. package/template-gx-design-thin/src/components/GDesign/utils/index.ts +0 -7
  93. package/template-gx-design-thin/src/components/GlobalLayout/Confirm/index.ts +0 -21
  94. package/template-gx-design-thin/src/components/GlobalLayout/Empty/index.vue +0 -18
  95. package/template-gx-design-thin/src/components/GlobalLayout/RightContent/index.tsx +0 -126
  96. package/template-gx-design-thin/src/components/GlobalLayout/RightContent/style.ts +0 -77
  97. package/template-gx-design-thin/src/components/GlobalLayout/Spin/index.tsx +0 -30
  98. package/template-gx-design-thin/src/components/PageLoading/index.tsx +0 -51
  99. package/template-gx-design-thin/src/components/index.ts +0 -6
  100. package/template-gx-design-thin/src/core/ant-design/index.ts +0 -10
  101. package/template-gx-design-thin/src/core/gx-admin-design/index.ts +0 -6
  102. package/template-gx-design-thin/src/core/gx-design/index.ts +0 -6
  103. package/template-gx-design-thin/src/core/gx-pro-design/index.ts +0 -8
  104. package/template-gx-design-thin/src/core/index.ts +0 -84
  105. package/template-gx-design-thin/src/design/ant-design/index.less +0 -4
  106. package/template-gx-design-thin/src/design/ant-design/layout.less +0 -22
  107. package/template-gx-design-thin/src/design/ant-design/menu.less +0 -48
  108. package/template-gx-design-thin/src/design/ant-design/spin.less +0 -23
  109. package/template-gx-design-thin/src/design/ant-design/tooltip.less +0 -7
  110. package/template-gx-design-thin/src/design/color.less +0 -1
  111. package/template-gx-design-thin/src/design/config.less +0 -5
  112. package/template-gx-design-thin/src/design/imageEditor.less +0 -180
  113. package/template-gx-design-thin/src/design/index.less +0 -95
  114. package/template-gx-design-thin/src/design/mixin.less +0 -65
  115. package/template-gx-design-thin/src/design/normalize.less +0 -391
  116. package/template-gx-design-thin/src/design/root.less +0 -3
  117. package/template-gx-design-thin/src/hooks/core/index.ts +0 -3
  118. package/template-gx-design-thin/src/hooks/core/useRequest/index.ts +0 -118
  119. package/template-gx-design-thin/src/hooks/event/index.ts +0 -3
  120. package/template-gx-design-thin/src/hooks/event/useClipboard.ts +0 -15
  121. package/template-gx-design-thin/src/hooks/web/index.ts +0 -5
  122. package/template-gx-design-thin/src/hooks/web/useThemeStyle.ts +0 -16
  123. package/template-gx-design-thin/src/layout/BasicLayout.vue +0 -123
  124. package/template-gx-design-thin/src/layout/BlankLayout.vue +0 -5
  125. package/template-gx-design-thin/src/layout/ContentView.vue +0 -50
  126. package/template-gx-design-thin/src/layout/IframeView.vue +0 -1
  127. package/template-gx-design-thin/src/layout/UserLayout.vue +0 -7
  128. package/template-gx-design-thin/src/main.ts +0 -34
  129. package/template-gx-design-thin/src/plugins/index.ts +0 -2
  130. package/template-gx-design-thin/src/router/guard/index.ts +0 -83
  131. package/template-gx-design-thin/src/router/guard/permissions.ts +0 -70
  132. package/template-gx-design-thin/src/router/guard/stateGuard.ts +0 -10
  133. package/template-gx-design-thin/src/router/helper/routeHelper.ts +0 -223
  134. package/template-gx-design-thin/src/router/helper/utils.ts +0 -19
  135. package/template-gx-design-thin/src/router/index.ts +0 -31
  136. package/template-gx-design-thin/src/router/routes/index.ts +0 -86
  137. package/template-gx-design-thin/src/router/routes/modules/dataSource.ts +0 -12
  138. package/template-gx-design-thin/src/services/common/index.ts +0 -11
  139. package/template-gx-design-thin/src/services/systemCenter/index.ts +0 -1
  140. package/template-gx-design-thin/src/services/systemCenter/menu.ts +0 -9
  141. package/template-gx-design-thin/src/services/userCenter/account.ts +0 -42
  142. package/template-gx-design-thin/src/services/userCenter/index.ts +0 -28
  143. package/template-gx-design-thin/src/store/index.ts +0 -32
  144. package/template-gx-design-thin/src/store/modules/dict.ts +0 -28
  145. package/template-gx-design-thin/src/store/modules/global.ts +0 -42
  146. package/template-gx-design-thin/src/store/modules/permission.ts +0 -19
  147. package/template-gx-design-thin/src/store/modules/routes.ts +0 -113
  148. package/template-gx-design-thin/src/store/modules/tabsRouter.ts +0 -76
  149. package/template-gx-design-thin/src/store/modules/user.ts +0 -136
  150. package/template-gx-design-thin/src/utils/accessToken.ts +0 -80
  151. package/template-gx-design-thin/src/utils/crypto/base64.ts +0 -101
  152. package/template-gx-design-thin/src/utils/crypto/index.ts +0 -57
  153. package/template-gx-design-thin/src/utils/env.ts +0 -50
  154. package/template-gx-design-thin/src/utils/fetchFile.ts +0 -81
  155. package/template-gx-design-thin/src/utils/index.ts +0 -123
  156. package/template-gx-design-thin/src/utils/pageTitle.ts +0 -20
  157. package/template-gx-design-thin/src/utils/request/XHR.ts +0 -139
  158. package/template-gx-design-thin/src/utils/request/axiosCancel.ts +0 -69
  159. package/template-gx-design-thin/src/utils/request/checkStatus.ts +0 -25
  160. package/template-gx-design-thin/src/utils/request/index.ts +0 -144
  161. package/template-gx-design-thin/src/utils/request/typings.ts +0 -171
  162. package/template-gx-design-thin/src/utils/storage.ts +0 -199
  163. package/template-gx-design-thin/src/utils/uploadFile.ts +0 -27
  164. package/template-gx-design-thin/src/utils/util.ts +0 -198
  165. package/template-gx-design-thin/src/utils/validate.ts +0 -216
  166. package/template-gx-design-thin/src/views/Iframe/index.vue +0 -76
  167. package/template-gx-design-thin/src/views/Page/one.vue +0 -13
  168. package/template-gx-design-thin/src/views/Page/two.vue +0 -13
  169. package/template-gx-design-thin/src/views/exception/403/index.vue +0 -7
  170. package/template-gx-design-thin/src/views/exception/404/index.vue +0 -9
  171. package/template-gx-design-thin/src/views/user/login/index.vue +0 -109
  172. package/template-gx-design-thin/src/views/user/login/style.less +0 -38
  173. package/template-gx-design-thin/tsconfig.json +0 -46
  174. package/template-gx-design-thin/types/ant-design-import.d.ts +0 -99
  175. package/template-gx-design-thin/types/auto-imports.d.ts +0 -81
  176. package/template-gx-design-thin/types/components.d.ts +0 -24
  177. package/template-gx-design-thin/types/config.d.ts +0 -44
  178. package/template-gx-design-thin/types/global.d.ts +0 -97
  179. package/template-gx-design-thin/types/mock.d.ts +0 -16
  180. package/template-gx-design-thin/types/module.d.ts +0 -20
  181. package/template-gx-design-thin/types/response.d.ts +0 -15
  182. package/template-gx-design-thin/unocss.config.ts +0 -101
  183. package/template-gx-design-thin/vite.config.ts +0 -120
  184. package/template-gx-design-thin/yarn.lock +0 -9492
@@ -1,131 +0,0 @@
1
- import fs from 'node:fs'
2
- import path, { resolve } from 'node:path'
3
- import dotenv from 'dotenv'
4
-
5
- export const rootPath = process.cwd()
6
-
7
- export function pathResolve(dir: string) {
8
- return resolve(process.cwd(), '.', dir)
9
- }
10
-
11
- /**
12
- * Whether to generate package preview
13
- */
14
- export function isReportMode(): boolean {
15
- return process.env.REPORT === 'true'
16
- }
17
-
18
- // Read all environment variable configuration files to process.env
19
- export function wrapperEnv(envConf: Recordable): ViteEnv {
20
- const ret: any = {}
21
-
22
- for (const envName of Object.keys(envConf)) {
23
- let realName = envConf[envName].replace(/\\n/g, '\n')
24
- realName = realName === 'true' ? true : realName === 'false' ? false : realName
25
-
26
- ret[envName] = realName
27
- process.env[envName] = realName
28
- }
29
- return ret
30
- }
31
-
32
- /**
33
- * 获取当前环境下生效的配置文件名
34
- */
35
- function getConfFiles() {
36
- const script = process.env.npm_lifecycle_script
37
- const reg = new RegExp('--mode ([a-z]+)')
38
- const result = reg.exec(script as string) as any
39
- if (result) {
40
- const mode = result[1] as string
41
- return [ '.env', `.env.${mode}` ]
42
- }
43
- return [ '.env', '.env.production' ]
44
- }
45
-
46
- /**
47
- * Get the environment variables starting with the specified prefix
48
- * @param match prefix
49
- * @param confFiles ext
50
- */
51
- export function getEnvConfig(confFiles = getConfFiles()): Partial<ViteEnv> {
52
- let envConfig: Partial<ViteEnv> = {}
53
- confFiles.forEach((item) => {
54
- try {
55
- const env = dotenv.parse(fs.readFileSync(path.resolve(process.cwd(), item)))
56
- envConfig = { ...envConfig, ...env }
57
- } catch (e) {
58
- console.error(`Error in parsing ${item}`, e)
59
- }
60
- })
61
- return envConfig
62
- }
63
-
64
- /**
65
- * Get user root directory
66
- * @param dir file path
67
- */
68
- export function getRootPath(...dir: string[]) {
69
- return path.resolve(process.cwd(), ...dir)
70
- }
71
-
72
- export function getDefaultPath(supportTs = true) {
73
- return path.resolve(process.cwd(), `src/main.${supportTs ? 'ts' : 'js'}`)
74
- }
75
-
76
- export function fileExists(f: string) {
77
- try {
78
- fs.accessSync(f, fs.constants.W_OK)
79
- return true
80
- } catch (error) {
81
- return false
82
- }
83
- }
84
-
85
- function q(t) {
86
- return t.reduce((n, e) => n + e)
87
- }
88
-
89
- function Gt(t, n?: number) {
90
- if (t === 0)
91
- return '0 Bytes'
92
- const e = 1024
93
- const r = n || 2
94
- const o = [ 'Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ]
95
- const s = Math.floor(Math.log(t) / Math.log(e))
96
- return `${Number.parseFloat((t / e ** s).toFixed(r))} ${o[s]}`
97
- }
98
-
99
- const ot = []
100
-
101
- export function getPackageSize({ folder, callBack, format = !0 }) {
102
- fs.readdir(folder, (err, files) => {
103
- if (err)
104
- throw err
105
-
106
- let index = 0
107
- const callBacks = () => {
108
- if (++index === files.length) {
109
- callBack(format ? Gt(q(ot)) : q(ot))
110
- }
111
- }
112
-
113
- files.forEach((p) => {
114
- fs.stat(`${folder}/${p}`, (err, stat) => {
115
- if (err)
116
- throw err
117
- if (stat.isFile()) {
118
- ot.push(stat.size)
119
- callBacks()
120
- } else {
121
- getPackageSize({
122
- folder: `${folder}/${p}`,
123
- callBack: callBacks
124
- })
125
- }
126
- })
127
- })
128
-
129
- files.length === 0 && callBack(0)
130
- })
131
- }
@@ -1,63 +0,0 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import { defaultSettings } from '../../config'
4
-
5
- const { cdnUrl, cdnModules } = defaultSettings
6
-
7
- function getModuleVersion(name: string): string {
8
- const pwd = process.cwd()
9
- const pkgFile = path.join(pwd, 'node_modules', name, 'package.json')
10
- if (fs.existsSync(pkgFile)) {
11
- const pkgJson = JSON.parse(fs.readFileSync(pkgFile, 'utf8'))
12
- return pkgJson.version
13
- }
14
-
15
- return ''
16
- }
17
-
18
- function isFullPath(path: string) {
19
- return path.startsWith('http:') || path.startsWith('https:') || path.startsWith('//')
20
- }
21
-
22
- function renderUrl(data: CdnModuleList & {
23
- version: string
24
- }) {
25
- const { path } = data
26
- if (isFullPath(path))
27
- return path
28
- return cdnUrl.replace(/\{name\}/g, data.name)
29
- .replace(/\{version\}/g, data.version)
30
- .replace(/\{path\}/g, path)
31
- }
32
-
33
- function getCdnModuleFiles() {
34
- return cdnModules.map(m => {
35
- const version = getModuleVersion(m.name)
36
- if (!version) {
37
- throw new Error(`modules: ${m.name} package.json file does not exist`)
38
- }
39
-
40
- let css = m.css || []
41
- if (!Array.isArray(css) && css) {
42
- css = [ css ]
43
- }
44
-
45
- return {
46
- js: renderUrl({
47
- ...m,
48
- version
49
- }),
50
- css
51
- }
52
- })
53
- }
54
-
55
- export function getExternalMap() {
56
- const externalMap = {}
57
- cdnModules.forEach((v) => {
58
- externalMap[v.name] = v.globalName
59
- })
60
- return externalMap
61
- }
62
-
63
- export default getCdnModuleFiles()
@@ -1,26 +0,0 @@
1
- import type { GetManualChunk } from 'rollup'
2
-
3
- const vendorLibs: { match: string[]; output: string }[] = [
4
- {
5
- match: ['ant-design-vue'],
6
- output: 'ant-design-vue',
7
- },
8
- {
9
- match: ['@gx-design-vue/pro-field'],
10
- output: 'pro-field',
11
- },
12
- {
13
- match: ['@gx-design-vue/pro-form'],
14
- output: 'pro-form',
15
- },
16
- ]
17
-
18
- export const configManualChunk: GetManualChunk = (id: string) => {
19
- if (/[\\/]node_modules[\\/]/.test(id)) {
20
- const matchItem = vendorLibs.find((item) => {
21
- const reg = new RegExp(`[\\/]node_modules[\\/]_?(${item.match.join('|')})(.*)`, 'ig')
22
- return reg.test(id)
23
- })
24
- return matchItem ? matchItem.output : null
25
- }
26
- }
@@ -1,91 +0,0 @@
1
- import colors from 'picocolors'
2
- import type { PluginOption } from 'vite'
3
- import { readPackageJSON } from 'pkg-types'
4
-
5
- import { getEnvConfig, rootPath } from '../../util'
6
- import { createContentHash, strToHex } from '../../util/hash'
7
-
8
- const GLOBAL_CONFIG_FILE_NAME = '_app.config.js'
9
- const PLUGIN_NAME = 'app-config'
10
-
11
- async function createAppConfigPlugin({
12
- isBuild
13
- }: {
14
- isBuild: boolean;
15
- }): Promise<PluginOption> {
16
- let publicPath: string
17
- let source: string
18
- if (!isBuild) {
19
- return {
20
- name: PLUGIN_NAME
21
- }
22
- }
23
- const { version = '' } = await readPackageJSON(rootPath)
24
-
25
- return {
26
- name: PLUGIN_NAME,
27
- async configResolved(_config) {
28
- const appTitle = _config?.env?.VITE_GLOB_APP_TITLE ?? ''
29
- publicPath = _config.base
30
- source = await getConfigSource(appTitle)
31
- },
32
- async transformIndexHtml(html) {
33
- publicPath = publicPath.endsWith('/') ? publicPath : `${publicPath}/`
34
-
35
- const appConfigSrc = `${
36
- publicPath || '/'
37
- }${GLOBAL_CONFIG_FILE_NAME}?v=${version}-${createContentHash(source)}`
38
-
39
- return {
40
- html,
41
- tags: [
42
- {
43
- tag: 'script',
44
- attrs: {
45
- src: appConfigSrc
46
- }
47
- }
48
- ]
49
- }
50
- },
51
- async generateBundle() {
52
- try {
53
- this.emitFile({
54
- type: 'asset',
55
- fileName: GLOBAL_CONFIG_FILE_NAME,
56
- source
57
- })
58
- } catch (error) {
59
- console.log(
60
- colors.red(`configuration file configuration file failed to package:\n${error}`)
61
- )
62
- }
63
- }
64
- }
65
- }
66
-
67
- /**
68
- * Get the configuration file variable name
69
- * @param env
70
- */
71
- const getVariableName = (title: string) => {
72
- return `__PRODUCTION__${strToHex(title) || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, '')
73
- }
74
-
75
- async function getConfigSource(appTitle: string) {
76
- const config = await getEnvConfig()
77
- const variableName = getVariableName(appTitle)
78
- const windowVariable = `window.${variableName}`
79
- // Ensure that the variable will not be modified
80
- let source = `${windowVariable}=${JSON.stringify(config)};`
81
- source += `
82
- Object.freeze(${windowVariable});
83
- Object.defineProperty(window, "${variableName}", {
84
- configurable: false,
85
- writable: false,
86
- });
87
- `.replace(/\s/g, '')
88
- return source
89
- }
90
-
91
- export { createAppConfigPlugin }
@@ -1,26 +0,0 @@
1
- import autoImport from 'unplugin-auto-import/vite'
2
- import Components from 'unplugin-vue-components/vite'
3
- import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
4
- import { defaultSettings } from '../../../config'
5
-
6
- const importsModules = [ 'vue', 'vue-router' ] as any
7
-
8
- export function createAutoImport() {
9
- const useCdnModules = defaultSettings.useCdn && defaultSettings.cdnModules.some(el => importsModules.includes(el.name))
10
- return [
11
- autoImport({
12
- include: [
13
- /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
14
- /\.vue$/, /\.vue\?vue/, // .vue
15
- /\.md$/ // .md
16
- ],
17
- imports: useCdnModules ? [] : importsModules,
18
- dts: 'types/auto-imports.d.ts',
19
- dirs: [ 'src/store' ]
20
- }),
21
- Components({
22
- resolvers: [ AntDesignVueResolver({ importStyle: false, resolveIcons: true }) ],
23
- dts: 'types/ant-design-import.d.ts'
24
- })
25
- ]
26
- }
@@ -1,31 +0,0 @@
1
- import type { Plugin } from 'vite'
2
-
3
- import compressPlugin from 'vite-plugin-compression'
4
-
5
- export function configCompressPlugin(
6
- compress: 'gzip' | 'brotli' | 'none',
7
- deleteOriginFile = false
8
- ): Plugin | Plugin[] {
9
- const compressList = compress.split(',')
10
-
11
- const plugins: Plugin[] = []
12
-
13
- if (compressList.includes('gzip')) {
14
- plugins.push(
15
- compressPlugin({
16
- ext: '.gz',
17
- deleteOriginFile
18
- })
19
- )
20
- }
21
- if (compressList.includes('brotli')) {
22
- plugins.push(
23
- compressPlugin({
24
- ext: '.br',
25
- algorithm: 'brotliCompress',
26
- deleteOriginFile
27
- })
28
- )
29
- }
30
- return plugins
31
- }
@@ -1,39 +0,0 @@
1
- import type { PluginOption } from 'vite'
2
- import { createHtmlPlugin } from 'vite-plugin-html'
3
-
4
- import cdnModules from '../cdn'
5
- import { GLOB_CONFIG_FILE_NAME } from '../../constant'
6
- import { defaultSettings } from '../../../config'
7
- import pkg from '../../../package.json'
8
-
9
- const { title, publicPath, useCdn } = defaultSettings
10
-
11
- export function configHtmlPlugin(_: ViteEnv, isBuild: boolean) {
12
- const path = publicPath.endsWith('/') ? publicPath : `${publicPath}/`
13
-
14
- const getAppConfigSrc = () => {
15
- return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`
16
- }
17
-
18
- const htmlPlugin: PluginOption[] = createHtmlPlugin({
19
- minify: isBuild,
20
- inject: {
21
- // Inject data into ejs template
22
- data: {
23
- VUE_APP_TITLE: title,
24
- injectScript: useCdn && isBuild ? cdnModules.map(e => e.js).filter(el => el) : [],
25
- injectLink: useCdn && isBuild ? cdnModules.map(e => e.css).filter(el => el) : []
26
- },
27
- // Embed the generated app.config.js file
28
- tags: isBuild
29
- ? [
30
- {
31
- tag: 'script',
32
- attrs: { src: getAppConfigSrc() }
33
- }
34
- ]
35
- : []
36
- }
37
- })
38
- return htmlPlugin
39
- }
@@ -1,75 +0,0 @@
1
- import type { PluginOption } from 'vite'
2
-
3
- import vue from '@vitejs/plugin-vue'
4
- import vueJsx from '@vitejs/plugin-vue-jsx'
5
- import VueDevTools from 'vite-plugin-vue-devtools'
6
- import legacy from '@vitejs/plugin-legacy'
7
-
8
- import vueSetupExtend from 'vite-plugin-vue-setup-extend'
9
-
10
- import Unocss from 'unocss/vite'
11
-
12
- import { configPwaConfig } from './pwa'
13
- import { configHtmlPlugin } from './html'
14
- import { configMockPlugin } from './mock'
15
- import viteNotice from './viteNotice'
16
- import { createAutoImport } from './autoImport'
17
- import { configCompressPlugin } from './compress'
18
- import { createAppConfigPlugin } from './appConfig'
19
- import { configVisualizerConfig } from './visualizer'
20
-
21
- export async function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
22
- const {
23
- VITE_APP_ENV,
24
- VITE_USE_MOCK,
25
- VITE_LEGACY,
26
- VITE_BUILD_COMPRESS,
27
- VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE
28
- } = viteEnv
29
-
30
- const isDev = VITE_APP_ENV === 'dev'
31
-
32
- const vitePlugins: PluginOption[] = [
33
- // have to
34
- vue(),
35
- // have to
36
- vueJsx()
37
- ]
38
-
39
- // vite-plugin-app-info
40
- vitePlugins.push(await createAppConfigPlugin({ isBuild }))
41
- // vite-plugin-vue-devtools
42
- vitePlugins.push(VueDevTools() as any)
43
- // vite-plugin-windicss
44
- vitePlugins.push(Unocss())
45
- // vite-plugin-vue-setup-extend
46
- vitePlugins.push(vueSetupExtend())
47
- // @vitejs/plugin-legacy
48
- VITE_LEGACY && isBuild && vitePlugins.push(legacy())
49
- // vite-plugin-html
50
- vitePlugins.push(configHtmlPlugin(viteEnv, isBuild))
51
- // vite-plugin-build-info
52
- vitePlugins.push(await viteNotice())
53
- // vite-plugin-mock
54
- const useMock = isDev || VITE_USE_MOCK
55
- useMock && vitePlugins.push(configMockPlugin())
56
-
57
- // rollup-plugin-visualizer
58
- vitePlugins.push(configVisualizerConfig())
59
-
60
- // unplugin-auto-import/vite
61
- vitePlugins.push(createAutoImport())
62
-
63
- // The following plugins only work in the production environment
64
- if (isBuild) {
65
- // rollup-plugin-gzip
66
- vitePlugins.push(
67
- configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE)
68
- )
69
-
70
- // vite-plugin-pwa
71
- vitePlugins.push(configPwaConfig(viteEnv))
72
- }
73
-
74
- return vitePlugins
75
- }
@@ -1,14 +0,0 @@
1
- import { viteMockServe } from './viteMock'
2
-
3
- export function configMockPlugin() {
4
- return viteMockServe({
5
- ignore: /^_/,
6
- mockPath: 'mock',
7
- enable: true,
8
- injectCode: `
9
- import { setupProdMockServer } from '../mock/_createProductionServer';
10
-
11
- setupProdMockServer();
12
- `,
13
- })
14
- }
@@ -1,31 +0,0 @@
1
- import { VitePWA } from 'vite-plugin-pwa'
2
-
3
- import { defaultSettings } from '../../../config'
4
-
5
- export function configPwaConfig(env: ViteEnv) {
6
- const { title, shortName } = defaultSettings
7
- const { VITE_USE_PWA } = env
8
-
9
- if (VITE_USE_PWA) {
10
- const pwaPlugin = VitePWA({
11
- manifest: {
12
- name: title || 'GX Pro Admin',
13
- short_name: shortName || 'gx_pro_admin',
14
- icons: [
15
- {
16
- src: './resource/img/pwa-192x192.png',
17
- sizes: '192x192',
18
- type: 'image/png'
19
- },
20
- {
21
- src: './resource/img/pwa-512x512.png',
22
- sizes: '512x512',
23
- type: 'image/png'
24
- }
25
- ]
26
- }
27
- })
28
- return pwaPlugin
29
- }
30
- return []
31
- }
@@ -1,14 +0,0 @@
1
- import { visualizer } from 'rollup-plugin-visualizer'
2
- import { isReportMode } from '../../util'
3
-
4
- export function configVisualizerConfig() {
5
- if (isReportMode()) {
6
- return visualizer({
7
- filename: './node_modules/.cache/visualizer/stats.html',
8
- open: true,
9
- gzipSize: true,
10
- brotliSize: true
11
- }) as Plugin
12
- }
13
- return []
14
- }
@@ -1,88 +0,0 @@
1
- import mockJs from 'mockjs'
2
- import { pathToRegexp } from 'path-to-regexp'
3
-
4
- const Mock = mockJs as any
5
-
6
- export function createProdMockServer(mockList: any[]) {
7
- Mock.XHR.prototype.__send = Mock.XHR.prototype.send
8
- Mock.XHR.prototype.send = function () {
9
- if (this.custom.xhr) {
10
- this.custom.xhr.withCredentials = this.withCredentials || false
11
-
12
- if (this.responseType) {
13
- this.custom.xhr.responseType = this.responseType
14
- }
15
- }
16
- if (this.custom.requestHeaders) {
17
- const headers: any = {}
18
- for (let k in this.custom.requestHeaders) {
19
- headers[k.toString().toLowerCase()] = this.custom.requestHeaders[k]
20
- }
21
- this.custom.options = Object.assign({}, this.custom.options, { headers })
22
- }
23
- this.__send.apply(this, arguments)
24
- }
25
-
26
- Mock.XHR.prototype.proxy_open = Mock.XHR.prototype.open
27
-
28
- Mock.XHR.prototype.open = function () {
29
- let responseType = this.responseType
30
- this.proxy_open(...arguments)
31
- if (this.custom.xhr) {
32
- if (responseType) {
33
- this.custom.xhr.responseType = responseType
34
- }
35
- }
36
- }
37
-
38
- for (const { url, method, response, timeout } of mockList) {
39
- __setupMock__(timeout)
40
- Mock.mock(
41
- pathToRegexp(url, undefined, { end: false }),
42
- method || 'get',
43
- __XHR2ExpressReqWrapper__(response)
44
- )
45
- }
46
- }
47
-
48
- function __param2Obj__(url: string) {
49
- const search = url.split('?')[1]
50
- if (!search) {
51
- return {}
52
- }
53
- return JSON.parse(
54
- '{"' +
55
- decodeURIComponent(search)
56
- .replace(/"/g, '\\"')
57
- .replace(/&/g, '","')
58
- .replace(/=/g, '":"')
59
- .replace(/\+/g, ' ') +
60
- '"}'
61
- )
62
- }
63
-
64
- function __XHR2ExpressReqWrapper__(handle: (d: any) => any) {
65
- return function (options: any) {
66
- let result = null
67
- if (typeof handle === 'function') {
68
- const { body, type, url, headers } = options
69
- result = handle({
70
- method: type,
71
- body: JSON.parse(body),
72
- query: __param2Obj__(url),
73
- headers
74
- })
75
- } else {
76
- result = handle
77
- }
78
-
79
- return Mock.mock(result)
80
- }
81
- }
82
-
83
- function __setupMock__(timeout = 0) {
84
- timeout &&
85
- Mock.setup({
86
- timeout
87
- })
88
- }