@gx-design-vue/create-gx-cli 0.1.19 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/README.md +1 -4
  2. package/dist/index.js +36 -48
  3. package/package.json +5 -3
  4. package/template-mobile-vant-cli/.editorconfig +19 -0
  5. package/template-mobile-vant-cli/.env +3 -0
  6. package/template-mobile-vant-cli/.env.development +17 -0
  7. package/template-mobile-vant-cli/.env.pro +28 -0
  8. package/template-mobile-vant-cli/.env.production +31 -0
  9. package/template-mobile-vant-cli/.eslintignore +15 -0
  10. package/template-mobile-vant-cli/.prettierignore +9 -0
  11. package/template-mobile-vant-cli/README.md +1 -0
  12. package/template-mobile-vant-cli/commitlint.config.cjs +32 -0
  13. package/template-mobile-vant-cli/config/default/defaultSettings.ts +70 -0
  14. package/template-mobile-vant-cli/config/default/network.ts +10 -0
  15. package/template-mobile-vant-cli/config/default/proxy.ts +50 -0
  16. package/template-mobile-vant-cli/config/default/theme.ts +3 -0
  17. package/template-mobile-vant-cli/config/index.ts +11 -0
  18. package/template-mobile-vant-cli/eslint.config.js +58 -0
  19. package/template-mobile-vant-cli/index.html +25 -0
  20. package/template-mobile-vant-cli/internal/vite-config/generate/generateModifyVars.ts +7 -0
  21. package/template-mobile-vant-cli/internal/vite-config/rollupOptions/index.ts +22 -0
  22. package/template-mobile-vant-cli/internal/vite-config/util/hash.ts +17 -0
  23. package/template-mobile-vant-cli/internal/vite-config/util/index.ts +132 -0
  24. package/template-mobile-vant-cli/internal/vite-config/vite/cdn.ts +65 -0
  25. package/template-mobile-vant-cli/internal/vite-config/vite/optimizer.ts +26 -0
  26. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/appConfig.ts +91 -0
  27. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/autoImport.ts +28 -0
  28. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/compress.ts +31 -0
  29. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/html.ts +32 -0
  30. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/index.ts +74 -0
  31. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/visualizer.ts +14 -0
  32. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/viteNotice.ts +40 -0
  33. package/template-mobile-vant-cli/mock/config/permissions.ts +15 -0
  34. package/template-mobile-vant-cli/mock/config/user/id.ts +5 -0
  35. package/template-mobile-vant-cli/mock/config/user/index.ts +96 -0
  36. package/template-mobile-vant-cli/mock/index.ts +55 -0
  37. package/template-mobile-vant-cli/mock/routers/table/index.fake.ts +22 -0
  38. package/template-mobile-vant-cli/mock/routers/user/account.fake.ts +52 -0
  39. package/template-mobile-vant-cli/mock/routers/user/index.fake.ts +46 -0
  40. package/template-mobile-vant-cli/mock/utils/crypto.ts +21 -0
  41. package/template-mobile-vant-cli/mock/utils/table.ts +96 -0
  42. package/template-mobile-vant-cli/mock/utils/util.ts +91 -0
  43. package/template-mobile-vant-cli/package.json +74 -0
  44. package/template-mobile-vant-cli/public/css/default.css +54 -0
  45. package/template-mobile-vant-cli/public/favicon.ico +0 -0
  46. package/template-mobile-vant-cli/src/App.vue +8 -0
  47. package/template-mobile-vant-cli/src/assets/logo.png +0 -0
  48. package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +29 -0
  49. package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +207 -0
  50. package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +17 -0
  51. package/template-mobile-vant-cli/src/components/TabsMenu/index.vue +45 -0
  52. package/template-mobile-vant-cli/src/core/gx-design/index.ts +7 -0
  53. package/template-mobile-vant-cli/src/core/index.ts +5 -0
  54. package/template-mobile-vant-cli/src/design/color.less +1 -0
  55. package/template-mobile-vant-cli/src/design/config.less +5 -0
  56. package/template-mobile-vant-cli/src/design/index.less +3 -0
  57. package/template-mobile-vant-cli/src/design/mixin.less +65 -0
  58. package/template-mobile-vant-cli/src/design/reset.less +39 -0
  59. package/template-mobile-vant-cli/src/design/root.less +3 -0
  60. package/template-mobile-vant-cli/src/design/vant/index.less +0 -0
  61. package/template-mobile-vant-cli/src/hooks/web/index.ts +5 -0
  62. package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +56 -0
  63. package/template-mobile-vant-cli/src/layout/BasicLayout/index.vue +18 -0
  64. package/template-mobile-vant-cli/src/layout/BasicLayout/style.less +3 -0
  65. package/template-mobile-vant-cli/src/layout/UserLayout/index.vue +18 -0
  66. package/template-mobile-vant-cli/src/layout/UserLayout/style.module.less +36 -0
  67. package/template-mobile-vant-cli/src/main.ts +34 -0
  68. package/template-mobile-vant-cli/src/pages/Account/details.vue +13 -0
  69. package/template-mobile-vant-cli/src/pages/Account/index.vue +102 -0
  70. package/template-mobile-vant-cli/src/pages/Home/index.vue +71 -0
  71. package/template-mobile-vant-cli/src/pages/user/login/index.vue +76 -0
  72. package/template-mobile-vant-cli/src/plugins/dayjs/index.ts +3 -0
  73. package/template-mobile-vant-cli/src/plugins/index.ts +2 -0
  74. package/template-mobile-vant-cli/src/router/guard/index.ts +18 -0
  75. package/template-mobile-vant-cli/src/router/guard/permissions.ts +41 -0
  76. package/template-mobile-vant-cli/src/router/guard/stateGuard.ts +10 -0
  77. package/template-mobile-vant-cli/src/router/index.ts +31 -0
  78. package/template-mobile-vant-cli/src/router/routes/index.ts +46 -0
  79. package/template-mobile-vant-cli/src/router/routes/modules/dataSource.ts +32 -0
  80. package/template-mobile-vant-cli/src/services/index.ts +31 -0
  81. package/template-mobile-vant-cli/src/services/userCenter/account.ts +42 -0
  82. package/template-mobile-vant-cli/src/services/userCenter/index.ts +28 -0
  83. package/template-mobile-vant-cli/src/store/index.ts +20 -0
  84. package/template-mobile-vant-cli/src/store/modules/global.ts +23 -0
  85. package/template-mobile-vant-cli/src/store/modules/user.ts +107 -0
  86. package/template-mobile-vant-cli/src/utils/accessToken.ts +97 -0
  87. package/template-mobile-vant-cli/src/utils/crypto/index.ts +56 -0
  88. package/template-mobile-vant-cli/src/utils/env.ts +50 -0
  89. package/template-mobile-vant-cli/src/utils/pageTitle.ts +20 -0
  90. package/template-mobile-vant-cli/src/utils/request/XHR.ts +137 -0
  91. package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +69 -0
  92. package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +25 -0
  93. package/template-mobile-vant-cli/src/utils/request/index.ts +155 -0
  94. package/template-mobile-vant-cli/src/utils/request/typings.ts +171 -0
  95. package/template-mobile-vant-cli/src/utils/storage.ts +215 -0
  96. package/template-mobile-vant-cli/src/utils/util.ts +27 -0
  97. package/template-mobile-vant-cli/src/utils/validate.ts +211 -0
  98. package/template-mobile-vant-cli/tsconfig.json +50 -0
  99. package/template-mobile-vant-cli/types/auto-imports.d.ts +80 -0
  100. package/template-mobile-vant-cli/types/components.d.ts +7 -0
  101. package/template-mobile-vant-cli/types/config.d.ts +56 -0
  102. package/template-mobile-vant-cli/types/global.d.ts +80 -0
  103. package/template-mobile-vant-cli/types/mock.d.ts +34 -0
  104. package/template-mobile-vant-cli/types/module.d.ts +61 -0
  105. package/template-mobile-vant-cli/types/response.d.ts +17 -0
  106. package/template-mobile-vant-cli/types/system.d.ts +58 -0
  107. package/template-mobile-vant-cli/types/vant-import.d.ts +25 -0
  108. package/template-mobile-vant-cli/unocss.config.ts +161 -0
  109. package/template-mobile-vant-cli/vite.config.ts +142 -0
  110. package/template-mobile-vant-html/README.md +4 -0
  111. package/template-mobile-vant-html/css/global.css +293 -0
  112. package/template-mobile-vant-html/css/global.css.map +1 -0
  113. package/template-mobile-vant-html/css/global.less +293 -0
  114. package/template-mobile-vant-html/css/index.css +20 -0
  115. package/template-mobile-vant-html/css/index.css.map +1 -0
  116. package/template-mobile-vant-html/css/index.less +21 -0
  117. package/template-mobile-vant-html/image/disconnected.svg +60 -0
  118. package/template-mobile-vant-html/image/empty.svg +52 -0
  119. package/template-mobile-vant-html/image/error.svg +53 -0
  120. package/template-mobile-vant-html/image/loading.svg +1 -0
  121. package/template-mobile-vant-html/index.html +91 -0
  122. package/template-mobile-vant-html/js/index.js +29 -0
  123. package/template-mobile-vant-html/js/plugin/day.min.js +1 -0
  124. package/template-mobile-vant-html/js/plugin/fastclick.js +730 -0
  125. package/template-mobile-vant-html/js/plugin/jquery.min.js +2 -0
  126. package/template-mobile-vant-html/js/plugin/rem.js +28 -0
  127. package/template-mobile-vant-html/js/utils/appUtil.js +70 -0
  128. package/template-mobile-vant-html/js/utils/config.js +3 -0
  129. package/template-mobile-vant-html/js/utils/request.js +61 -0
  130. package/template-mobile-vant-html/js/utils/utils.js +65 -0
  131. package/template-mobile-vant-html/js/utils/validate.js +292 -0
  132. package/template-vite-project/.env +5 -0
  133. package/template-vite-project/.env.development +5 -0
  134. package/template-vite-project/.env.pro +5 -0
  135. package/template-vite-project/.env.production +5 -0
  136. package/template-vite-project/README.md +5 -0
  137. package/template-vite-project/_gitignore +24 -0
  138. package/template-vite-project/index.html +46 -0
  139. package/template-vite-project/internal/proxy/index.ts +47 -0
  140. package/template-vite-project/internal/vite/generate/generateModifyVars.ts +9 -0
  141. package/template-vite-project/internal/vite/rollupOptions/index.ts +18 -0
  142. package/template-vite-project/internal/vite/util/hash.ts +17 -0
  143. package/template-vite-project/internal/vite/util/index.ts +132 -0
  144. package/template-vite-project/internal/vite/vite/cdn.ts +65 -0
  145. package/template-vite-project/internal/vite/vite/plugin/appConfig.ts +91 -0
  146. package/template-vite-project/internal/vite/vite/plugin/autoImport.ts +28 -0
  147. package/template-vite-project/internal/vite/vite/plugin/compress.ts +31 -0
  148. package/template-vite-project/internal/vite/vite/plugin/html.ts +24 -0
  149. package/template-vite-project/internal/vite/vite/plugin/index.ts +72 -0
  150. package/template-vite-project/internal/vite/vite/plugin/visualizer.ts +14 -0
  151. package/template-vite-project/internal/vite/vite/plugin/viteNotice.ts +40 -0
  152. package/template-vite-project/node_modules/.bin/cross-env +21 -0
  153. package/template-vite-project/node_modules/.bin/cross-env-shell +21 -0
  154. package/template-vite-project/node_modules/.bin/esbuild +21 -0
  155. package/template-vite-project/node_modules/.bin/jiti +21 -0
  156. package/template-vite-project/node_modules/.bin/lessc +21 -0
  157. package/template-vite-project/node_modules/.bin/parser +21 -0
  158. package/template-vite-project/node_modules/.bin/rollup +21 -0
  159. package/template-vite-project/node_modules/.bin/terser +21 -0
  160. package/template-vite-project/node_modules/.bin/tsc +21 -0
  161. package/template-vite-project/node_modules/.bin/tsserver +21 -0
  162. package/template-vite-project/node_modules/.bin/vite +21 -0
  163. package/template-vite-project/node_modules/.bin/vue-tsc +21 -0
  164. package/template-vite-project/node_modules/.bin/yaml +21 -0
  165. package/template-vite-project/package.json +38 -0
  166. package/template-vite-project/public/css/index.css +89 -0
  167. package/template-vite-project/public/css/normalize.css +396 -0
  168. package/template-vite-project/public/vite.svg +1 -0
  169. package/template-vite-project/src/App.vue +30 -0
  170. package/template-vite-project/src/assets/vue.svg +1 -0
  171. package/template-vite-project/src/components/HelloWorld.vue +41 -0
  172. package/template-vite-project/src/design/config.less +0 -0
  173. package/template-vite-project/src/design/index.less +0 -0
  174. package/template-vite-project/src/main.ts +14 -0
  175. package/template-vite-project/src/utils/env.ts +50 -0
  176. package/template-vite-project/tsconfig.app.json +59 -0
  177. package/template-vite-project/tsconfig.json +7 -0
  178. package/template-vite-project/tsconfig.node.json +28 -0
  179. package/template-vite-project/types/global.d.ts +33 -0
  180. package/template-vite-project/unocss.config.ts +208 -0
  181. package/template-vite-project/vite.config.ts +88 -0
@@ -0,0 +1,50 @@
1
+ /**
2
+ * 在生产环境 代理是无法生效的,所以这里没有生产环境的配置
3
+ * The agent cannot take effect in the production environment
4
+ * so there is no configuration of the production environment
5
+ * For details, please see
6
+ * https://pro.ant.design/docs/deploy
7
+ */
8
+ import type { ProxyOptions } from 'vite'
9
+ import { isObject, isString } from '@gx-design-vue/pro-utils'
10
+ import defaultSettings from './defaultSettings'
11
+
12
+ type ProxyTargetList = ProxyOptions & { rewrite: (path: string) => string }
13
+
14
+ export function createProxy(prefix) {
15
+ const { proxy } = defaultSettings
16
+
17
+ const ret: Record<ViteEnv['VITE_APP_ENV'], Record<string, Partial<ProxyTargetList>>> = {
18
+ dev: {
19
+ [prefix]: {}
20
+ },
21
+ pro: {
22
+ [prefix]: {}
23
+ }
24
+ }
25
+
26
+ if (isObject(proxy.target)) {
27
+ Object.keys(proxy.target).forEach((prefix) => {
28
+ const proxyOptions: ProxyTargetList = {
29
+ target: `${proxy.target[prefix]}`,
30
+ changeOrigin: true,
31
+ ws: true,
32
+ rewrite: path => path.replace(new RegExp(`^${prefix}`), '')
33
+ }
34
+
35
+ ret.dev[prefix] = proxyOptions
36
+ ret.pro[prefix] = proxyOptions
37
+ })
38
+ } else if (isString(proxy.target)) {
39
+ const proxyOptions: ProxyTargetList = {
40
+ target: `${proxy.target}`,
41
+ changeOrigin: true,
42
+ ws: true,
43
+ rewrite: path => path.replace(new RegExp(`^${prefix}`), '')
44
+ }
45
+ ret.dev[prefix] = proxyOptions
46
+ ret.pro[prefix] = proxyOptions
47
+ }
48
+
49
+ return ret
50
+ }
@@ -0,0 +1,3 @@
1
+ export default {
2
+ colorPrimary: '#1677FF'
3
+ } as ProAliasToken
@@ -0,0 +1,11 @@
1
+ import defaultSettings from './default/defaultSettings'
2
+ import network from './default/network'
3
+ import theme from './default/theme'
4
+
5
+ export * from './default/proxy'
6
+
7
+ export {
8
+ defaultSettings,
9
+ network,
10
+ theme
11
+ }
@@ -0,0 +1,58 @@
1
+ import antFuEslint from '@antfu/eslint-config'
2
+
3
+ export default antFuEslint({
4
+ vue: true,
5
+ vueJsx: true,
6
+ typescript: true,
7
+ gitignore: true,
8
+ markdown: true,
9
+ ignores: [
10
+ 'src/assets/**/*.js',
11
+ 'public',
12
+ 'tsconfig.*.json',
13
+ 'tsconfig.json'
14
+ ]
15
+ }, {
16
+ rules: {
17
+ 'curly': 0,
18
+ 'perfectionist/sort-exports': 0,
19
+ 'vue/eqeqeq': 0,
20
+ 'no-console': 0,
21
+ 'vue/no-unused-refs': 0,
22
+ 'no-template-curly-in-string': 0,
23
+ 'vue/prop-name-casing': 0,
24
+ 'vue/html-comment-content-spacing': 0,
25
+ 'style/indent-binary-ops': 0,
26
+ 'antfu/if-newline': 0,
27
+ 'import/order': 0,
28
+ 'style/quote-props': 0,
29
+ 'style/brace-style': 0,
30
+ 'style/comma-dangle': 0,
31
+ 'style/multiline-ternary': 0,
32
+ 'prefer-regex-literals': 0,
33
+ 'antfu/top-level-function': 0,
34
+ 'vue/array-bracket-spacing': 0,
35
+ 'style/array-bracket-spacing': 0,
36
+ 'node/prefer-global/process': 0,
37
+ 'style/indent': 0,
38
+ 'prefer-template': 0,
39
+ 'dot-notation': 0,
40
+ 'no-cond-assign': 0,
41
+ 'no-useless-computed-key': 0,
42
+ 'node/no-deprecated-api': 0,
43
+ 'antfu/consistent-list-newline': 0,
44
+ 'import/no-mutable-exports': 0,
45
+ 'style/member-delimiter-style': 0,
46
+ 'unused-imports/no-unused-imports': 0,
47
+ 'eslint-comments/no-unlimited-disable': 0,
48
+ 'no-async-promise-executor': 0,
49
+ 'unicorn/escape-case': 0,
50
+ 'ts/ban-ts-comment': 0,
51
+ 'ts/prefer-ts-expect-error': 0,
52
+ 'ts/method-signature-style': 0,
53
+ 'style/no-trailing-spaces': 0,
54
+ 'ts/consistent-type-imports': 0,
55
+ 'style/type-generic-spacing': 0,
56
+ 'prefer-promise-reject-errors': 0
57
+ }
58
+ })
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" href="/favicon.ico" type="image/x-jpg" />
6
+ <meta
7
+ name="viewport"
8
+ content="width=device-width,viewport-fit=cover,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"
9
+ />
10
+ <title><%= VUE_APP_TITLE %></title>
11
+ <% for (var i in injectLink) { %>
12
+ <link rel="stylesheet" type="text/css" href="<%= injectLink[i] %>" />
13
+ <% } %>
14
+ </head>
15
+ <body>
16
+ <div id="app">
17
+ <%- injectAppContent %>
18
+ </div>
19
+ <% for (var i in injectScript) { %>
20
+ <script type="text/javascript" src="<%= injectScript[i] %>"></script>
21
+ <% } %>
22
+ <script type="module" src="/src/main.ts"></script>
23
+ <%- injectVlogScript %>
24
+ </body>
25
+ </html>
@@ -0,0 +1,7 @@
1
+ import { resolve } from 'node:path'
2
+
3
+ export function generateModifyVars() {
4
+ return {
5
+ hack: `true; @import (reference) "${resolve('src/design/config.less')}";`
6
+ }
7
+ }
@@ -0,0 +1,22 @@
1
+ import type { RollupOptions } from 'rollup'
2
+ import externalGlobals from 'rollup-plugin-external-globals'
3
+ import { pathResolve } from '../util'
4
+ import { getExternalMap } from '../vite/cdn'
5
+ import { configManualChunk } from '../vite/optimizer'
6
+
7
+ export default function (useCdn: boolean) {
8
+ return {
9
+ input: {
10
+ index: pathResolve('index.html')
11
+ },
12
+ // 静态资源分类打包
13
+ output: {
14
+ manualChunks: configManualChunk,
15
+ chunkFileNames: 'static/js/[name]-[hash].js',
16
+ entryFileNames: 'static/js/[name]-[hash].js',
17
+ assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
18
+ },
19
+ external: useCdn ? Object.keys(getExternalMap()) : [],
20
+ plugins: useCdn ? [ externalGlobals(getExternalMap()) ] : []
21
+ } as RollupOptions
22
+ }
@@ -0,0 +1,17 @@
1
+ import { createHash } from 'node:crypto'
2
+
3
+ function createContentHash(content: string, hashLSize = 12) {
4
+ const hash = createHash('sha256').update(content)
5
+ return hash.digest('hex').slice(0, hashLSize)
6
+ }
7
+
8
+ function strToHex(str: string) {
9
+ const result: string[] = []
10
+ for (let i = 0; i < str.length; ++i) {
11
+ const hex = str.charCodeAt(i).toString(16)
12
+ result.push((`000${hex}`).slice(-4))
13
+ }
14
+ return result.join('').toUpperCase()
15
+ }
16
+
17
+ export { createContentHash, strToHex }
@@ -0,0 +1,132 @@
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
+ // eslint-disable-next-line unused-imports/no-unused-vars
81
+ } catch (error) {
82
+ return false
83
+ }
84
+ }
85
+
86
+ function q(t) {
87
+ return t.reduce((n, e) => n + e)
88
+ }
89
+
90
+ function Gt(t, n?: number) {
91
+ if (t === 0)
92
+ return '0 Bytes'
93
+ const e = 1024
94
+ const r = n || 2
95
+ const o = [ 'Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ]
96
+ const s = Math.floor(Math.log(t) / Math.log(e))
97
+ return `${Number.parseFloat((t / e ** s).toFixed(r))} ${o[s]}`
98
+ }
99
+
100
+ const ot: number[] = []
101
+
102
+ export function getPackageSize({ folder, callBack, format = !0 }) {
103
+ fs.readdir(folder, (err, files) => {
104
+ if (err)
105
+ throw err
106
+
107
+ let index = 0
108
+ const callBacks = () => {
109
+ if (++index === files.length) {
110
+ callBack(format ? Gt(q(ot)) : q(ot))
111
+ }
112
+ }
113
+
114
+ files.forEach((p) => {
115
+ fs.stat(`${folder}/${p}`, (err, stat) => {
116
+ if (err)
117
+ throw err
118
+ if (stat.isFile()) {
119
+ ot.push(stat.size)
120
+ callBacks()
121
+ } else {
122
+ getPackageSize({
123
+ folder: `${folder}/${p}`,
124
+ callBack: callBacks
125
+ })
126
+ }
127
+ })
128
+ })
129
+
130
+ files.length === 0 && callBack(0)
131
+ })
132
+ }
@@ -0,0 +1,65 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { defaultSettings } from '../../../config'
4
+
5
+ const { cdn } = defaultSettings
6
+
7
+ const { modules = [], url = '' } = cdn
8
+
9
+ function getModuleVersion(name: string): string {
10
+ const pwd = process.cwd()
11
+ const pkgFile = path.join(pwd, 'node_modules', name, 'package.json')
12
+ if (fs.existsSync(pkgFile)) {
13
+ const pkgJson = JSON.parse(fs.readFileSync(pkgFile, 'utf8'))
14
+ return pkgJson.version
15
+ }
16
+
17
+ return ''
18
+ }
19
+
20
+ function isFullPath(path: string) {
21
+ return path.startsWith('http:') || path.startsWith('https:') || path.startsWith('//')
22
+ }
23
+
24
+ function renderUrl(data: CdnModuleList & {
25
+ version: string
26
+ }) {
27
+ const { path } = data
28
+ if (isFullPath(path))
29
+ return path
30
+ return url.replace(/\{name\}/g, data.name)
31
+ .replace(/\{version\}/g, data.version)
32
+ .replace(/\{path\}/g, path)
33
+ }
34
+
35
+ function getCdnModuleFiles() {
36
+ return modules.map((m) => {
37
+ const version = getModuleVersion(m.name)
38
+ if (!version) {
39
+ throw new Error(`modules: ${m.name} package.json file does not exist`)
40
+ }
41
+
42
+ let css = m.css || [] as string[]
43
+ if (!Array.isArray(css) && css) {
44
+ css = [ css ]
45
+ }
46
+
47
+ return {
48
+ js: renderUrl({
49
+ ...m,
50
+ version
51
+ }),
52
+ css
53
+ }
54
+ })
55
+ }
56
+
57
+ export function getExternalMap() {
58
+ const externalMap = {}
59
+ modules.forEach((v) => {
60
+ externalMap[v.name] = v.globalName
61
+ })
62
+ return externalMap
63
+ }
64
+
65
+ export default getCdnModuleFiles()
@@ -0,0 +1,26 @@
1
+ import type { GetManualChunk } from 'rollup'
2
+
3
+ const vendorLibs: { match: string[]; output: string }[] = [
4
+ {
5
+ match: ['vant'],
6
+ output: 'vant',
7
+ },
8
+ {
9
+ match: ['crypto-js'],
10
+ output: 'crypto-js',
11
+ },
12
+ {
13
+ match: ['lodash-es'],
14
+ output: 'lodash-es',
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('|')})(.*)`, 'gi')
22
+ return reg.test(id)
23
+ })
24
+ return matchItem ? matchItem.output : null
25
+ }
26
+ }
@@ -0,0 +1,91 @@
1
+ import type { PluginOption } from 'vite'
2
+ import colors from 'picocolors'
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 }
@@ -0,0 +1,28 @@
1
+ import { VantResolver } from '@vant/auto-import-resolver'
2
+ import autoImport from 'unplugin-auto-import/vite'
3
+ import Components from 'unplugin-vue-components/vite'
4
+ import { defaultSettings } from '../../../../config'
5
+
6
+ const importsModules = [ 'vue', 'vue-router' ] as any
7
+
8
+ const { modules = [], use } = defaultSettings.cdn
9
+
10
+ export function createAutoImport() {
11
+ const useCdnModules = use && modules.some(el => importsModules.includes(el.name))
12
+ return [
13
+ autoImport({
14
+ include: [
15
+ /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
16
+ /\.vue$/, /\.vue\?vue/, // .vue
17
+ /\.md$/ // .md
18
+ ],
19
+ imports: useCdnModules ? [] : importsModules,
20
+ dts: 'types/auto-imports.d.ts',
21
+ dirs: [ 'src/store' ]
22
+ }),
23
+ Components({
24
+ resolvers: [ VantResolver() ],
25
+ dts: 'types/vant-import.d.ts'
26
+ })
27
+ ]
28
+ }
@@ -0,0 +1,31 @@
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
+ }
@@ -0,0 +1,32 @@
1
+ import type { PluginOption } from 'vite'
2
+ import { createHtmlPlugin } from 'vite-plugin-html'
3
+
4
+ import { defaultSettings } from '../../../../config'
5
+ import cdnModules from '../cdn'
6
+
7
+ const { cdn, system } = defaultSettings
8
+
9
+ const startLoadingCss = system.appInit.loading ? [ '/css/default.css' ] : []
10
+
11
+ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
12
+ const htmlPlugin: PluginOption[] = createHtmlPlugin({
13
+ minify: isBuild,
14
+ inject: {
15
+ // Inject data into ejs template
16
+ data: {
17
+ VUE_APP_TITLE: system.title,
18
+ injectVlogScript: env.VITE_USE_V_CONSOLE
19
+ ? `<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script><script>var vConsole = new window.VConsole();</script>`
20
+ : '',
21
+ injectAppContent: system.appInit.loading
22
+ ? `<div class="gx-toast-loading"><div class="gx-toast-loading-cont"><span class="gx-toast-svg"><svg class="van-loading__circular" viewBox="25 25 50 50"><circle cx="50" cy="50" r="20" fill="none"></circle></svg></span><span class="gx-toast-svg-text">${system.appInit.loading?.text}</span></div></div>`
23
+ : '',
24
+ injectScript: cdn.use && isBuild ? cdnModules.map(e => e.js).filter(el => el) : [],
25
+ injectLink: cdn.use && isBuild
26
+ ? cdnModules.map(e => e.css).filter(el => el).concat(startLoadingCss as string[])
27
+ : startLoadingCss
28
+ }
29
+ }
30
+ })
31
+ return htmlPlugin
32
+ }
@@ -0,0 +1,74 @@
1
+ import type { PluginOption } from 'vite'
2
+
3
+ import legacy from '@vitejs/plugin-legacy'
4
+ import vue from '@vitejs/plugin-vue'
5
+ import vueJsx from '@vitejs/plugin-vue-jsx'
6
+ import Unocss from 'unocss/vite'
7
+ import TurboConsole from 'unplugin-turbo-console/vite'
8
+ // @ts-ignore
9
+ import { vitePluginFakeServer } from 'vite-plugin-fake-server'
10
+
11
+ import { createAppConfigPlugin } from './appConfig'
12
+ import { createAutoImport } from './autoImport'
13
+ import { configCompressPlugin } from './compress'
14
+ import { configHtmlPlugin } from './html'
15
+ import { configVisualizerConfig } from './visualizer'
16
+ import viteNotice from './viteNotice'
17
+
18
+ export async function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
19
+ const {
20
+ VITE_APP_ENV,
21
+ VITE_USE_MOCK,
22
+ VITE_LEGACY,
23
+ VITE_BUILD_COMPRESS,
24
+ VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE
25
+ } = viteEnv
26
+
27
+ const isDev = VITE_APP_ENV === 'dev'
28
+
29
+ const vitePlugins: PluginOption[] = [
30
+ // have to
31
+ vue(),
32
+ // have to
33
+ vueJsx()
34
+ ]
35
+
36
+ // vite-plugin-app-info
37
+ vitePlugins.push(await createAppConfigPlugin({ isBuild }))
38
+ // vite-plugin-windicss
39
+ vitePlugins.push(Unocss())
40
+
41
+ // unplugin-turbo-console
42
+ isDev && vitePlugins.push(TurboConsole())
43
+ // @vitejs/plugin-legacy
44
+ VITE_LEGACY && isBuild && vitePlugins.push(legacy({
45
+ // 设置目标浏览器,browserslist 配置语法
46
+ targets: ['Android >= 7', 'chrome < 60', 'edge < 15'],
47
+ }))
48
+ // vite-plugin-html
49
+ vitePlugins.push(configHtmlPlugin(viteEnv, isBuild))
50
+ // vite-plugin-build-info
51
+ vitePlugins.push(await viteNotice())
52
+ // vite-plugin-mock
53
+ const useMock = isDev || VITE_USE_MOCK
54
+ useMock && vitePlugins.push(vitePluginFakeServer({
55
+ include: 'mock/routers',
56
+ enableProd: VITE_USE_MOCK
57
+ }),)
58
+
59
+ // rollup-plugin-visualizer
60
+ vitePlugins.push(configVisualizerConfig())
61
+
62
+ // unplugin-auto-import/vite
63
+ vitePlugins.push(createAutoImport())
64
+
65
+ // The following plugins only work in the production environment
66
+ if (isBuild) {
67
+ // rollup-plugin-gzip
68
+ vitePlugins.push(
69
+ configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE)
70
+ )
71
+ }
72
+
73
+ return vitePlugins
74
+ }