@gx-design-vue/create-gx-cli 0.1.14 → 0.1.16

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 (124) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +7 -4
  3. package/src/main.js +7 -7
  4. package/template-mobile-vant-cli/.env +3 -0
  5. package/template-mobile-vant-cli/.env.development +4 -6
  6. package/template-mobile-vant-cli/.env.pro +16 -7
  7. package/template-mobile-vant-cli/.env.production +21 -9
  8. package/template-mobile-vant-cli/commitlint.config.cjs +32 -0
  9. package/template-mobile-vant-cli/config/default/defaultSettings.ts +70 -0
  10. package/template-mobile-vant-cli/config/default/network.ts +10 -0
  11. package/template-mobile-vant-cli/config/default/proxy.ts +50 -0
  12. package/template-mobile-vant-cli/config/default/theme.ts +3 -0
  13. package/template-mobile-vant-cli/config/index.ts +11 -0
  14. package/template-mobile-vant-cli/eslint.config.js +10 -2
  15. package/template-mobile-vant-cli/index.html +22 -21
  16. package/template-mobile-vant-cli/{build → internal/vite-config/generate}/generateModifyVars.ts +1 -1
  17. package/template-mobile-vant-cli/internal/vite-config/rollupOptions/index.ts +22 -0
  18. package/template-mobile-vant-cli/internal/vite-config/util/hash.ts +17 -0
  19. package/template-mobile-vant-cli/internal/vite-config/util/index.ts +132 -0
  20. package/template-mobile-vant-cli/internal/vite-config/vite/cdn.ts +65 -0
  21. package/template-mobile-vant-cli/{build → internal/vite-config/vite}/optimizer.ts +9 -1
  22. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/appConfig.ts +91 -0
  23. package/template-mobile-vant-cli/{build → internal/vite-config/vite}/plugin/autoImport.ts +7 -3
  24. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/compress.ts +31 -0
  25. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/html.ts +32 -0
  26. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/index.ts +74 -0
  27. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/visualizer.ts +14 -0
  28. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/viteNotice.ts +40 -0
  29. package/template-mobile-vant-cli/mock/config/permissions.ts +15 -0
  30. package/template-mobile-vant-cli/mock/config/user/id.ts +5 -0
  31. package/template-mobile-vant-cli/mock/config/user/index.ts +96 -0
  32. package/template-mobile-vant-cli/mock/index.ts +55 -0
  33. package/template-mobile-vant-cli/mock/routers/table/index.fake.ts +22 -0
  34. package/template-mobile-vant-cli/mock/routers/user/account.fake.ts +52 -0
  35. package/template-mobile-vant-cli/mock/routers/user/index.fake.ts +46 -0
  36. package/template-mobile-vant-cli/mock/utils/crypto.ts +21 -0
  37. package/template-mobile-vant-cli/mock/utils/table.ts +96 -0
  38. package/template-mobile-vant-cli/mock/utils/util.ts +91 -0
  39. package/template-mobile-vant-cli/package.json +51 -34
  40. package/template-mobile-vant-cli/public/css/default.css +54 -0
  41. package/template-mobile-vant-cli/src/App.vue +6 -2
  42. package/template-mobile-vant-cli/src/assets/logo.png +0 -0
  43. package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +1 -1
  44. package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +108 -16
  45. package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +5 -2
  46. package/template-mobile-vant-cli/src/components/TabsMenu/index.vue +45 -0
  47. package/template-mobile-vant-cli/src/core/gx-design/index.ts +1 -1
  48. package/template-mobile-vant-cli/src/core/index.ts +0 -7
  49. package/template-mobile-vant-cli/src/design/color.less +1 -0
  50. package/template-mobile-vant-cli/src/design/config.less +5 -0
  51. package/template-mobile-vant-cli/src/design/index.less +1 -1
  52. package/template-mobile-vant-cli/src/design/mixin.less +65 -0
  53. package/template-mobile-vant-cli/src/design/reset.less +16 -132
  54. package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +7 -9
  55. package/template-mobile-vant-cli/src/layout/{BasicLayout.vue → BasicLayout/index.vue} +3 -1
  56. package/template-mobile-vant-cli/src/layout/BasicLayout/style.less +3 -0
  57. package/template-mobile-vant-cli/src/layout/UserLayout/index.vue +18 -0
  58. package/template-mobile-vant-cli/src/layout/UserLayout/style.module.less +36 -0
  59. package/template-mobile-vant-cli/src/main.ts +16 -9
  60. package/template-mobile-vant-cli/src/pages/Account/details.vue +13 -0
  61. package/template-mobile-vant-cli/src/pages/Account/index.vue +102 -0
  62. package/template-mobile-vant-cli/src/pages/{home.vue → Home/index.vue} +5 -5
  63. package/template-mobile-vant-cli/src/pages/user/login/index.vue +74 -0
  64. package/template-mobile-vant-cli/src/plugins/dayjs/index.ts +3 -0
  65. package/template-mobile-vant-cli/src/plugins/index.ts +2 -0
  66. package/template-mobile-vant-cli/src/router/guard/index.ts +18 -0
  67. package/template-mobile-vant-cli/src/router/guard/permissions.ts +41 -0
  68. package/template-mobile-vant-cli/src/router/guard/stateGuard.ts +10 -0
  69. package/template-mobile-vant-cli/src/router/index.ts +21 -15
  70. package/template-mobile-vant-cli/src/router/routes/index.ts +46 -0
  71. package/template-mobile-vant-cli/src/router/routes/modules/dataSource.ts +32 -0
  72. package/template-mobile-vant-cli/src/services/userCenter/account.ts +42 -0
  73. package/template-mobile-vant-cli/src/services/userCenter/index.ts +28 -0
  74. package/template-mobile-vant-cli/src/store/index.ts +4 -1
  75. package/template-mobile-vant-cli/src/store/modules/global.ts +6 -13
  76. package/template-mobile-vant-cli/src/store/modules/user.ts +107 -0
  77. package/template-mobile-vant-cli/src/utils/accessToken.ts +97 -0
  78. package/template-mobile-vant-cli/src/utils/crypto/index.ts +3 -4
  79. package/template-mobile-vant-cli/src/utils/env.ts +2 -2
  80. package/template-mobile-vant-cli/src/utils/pageTitle.ts +12 -6
  81. package/template-mobile-vant-cli/src/utils/request/XHR.ts +9 -11
  82. package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +5 -5
  83. package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +18 -2
  84. package/template-mobile-vant-cli/src/utils/request/index.ts +36 -23
  85. package/template-mobile-vant-cli/src/utils/storage.ts +49 -32
  86. package/template-mobile-vant-cli/src/utils/validate.ts +31 -36
  87. package/template-mobile-vant-cli/tsconfig.json +17 -9
  88. package/template-mobile-vant-cli/types/auto-imports.d.ts +18 -2
  89. package/template-mobile-vant-cli/types/components.d.ts +2 -7
  90. package/template-mobile-vant-cli/types/config.d.ts +56 -0
  91. package/template-mobile-vant-cli/types/global.d.ts +62 -21
  92. package/template-mobile-vant-cli/types/mock.d.ts +34 -0
  93. package/template-mobile-vant-cli/types/module.d.ts +33 -0
  94. package/template-mobile-vant-cli/types/response.d.ts +3 -1
  95. package/template-mobile-vant-cli/types/system.d.ts +58 -0
  96. package/template-mobile-vant-cli/types/vant-import.d.ts +16 -5
  97. package/template-mobile-vant-cli/unocss.config.ts +120 -66
  98. package/template-mobile-vant-cli/vite.config.ts +78 -81
  99. package/template-mobile-vant-cli/build/cdn.ts +0 -5
  100. package/template-mobile-vant-cli/build/plugin/html.ts +0 -26
  101. package/template-mobile-vant-cli/build/plugin/index.ts +0 -42
  102. package/template-mobile-vant-cli/build/plugin/mock.ts +0 -14
  103. package/template-mobile-vant-cli/build/plugin/viteMock/client.ts +0 -88
  104. package/template-mobile-vant-cli/build/plugin/viteMock/createMockServer.ts +0 -271
  105. package/template-mobile-vant-cli/build/plugin/viteMock/index.ts +0 -69
  106. package/template-mobile-vant-cli/build/plugin/viteMock/types.ts +0 -48
  107. package/template-mobile-vant-cli/build/plugin/viteMock/utils.ts +0 -48
  108. package/template-mobile-vant-cli/build/script/postBuild.ts +0 -14
  109. package/template-mobile-vant-cli/mock/_createProductionServer.ts +0 -19
  110. package/template-mobile-vant-cli/mock/utils.ts +0 -9
  111. package/template-mobile-vant-cli/postcss.config.cjs +0 -8
  112. package/template-mobile-vant-cli/prettier.config.cjs +0 -18
  113. package/template-mobile-vant-cli/public/js/flexible.js +0 -44
  114. package/template-mobile-vant-cli/src/core/vant-design/index.ts +0 -4
  115. package/template-mobile-vant-cli/src/design/vant.less +0 -2
  116. package/template-mobile-vant-cli/src/global.less +0 -1
  117. package/template-mobile-vant-cli/src/layout/basicLayout.less +0 -11
  118. package/template-mobile-vant-cli/src/router/routes.ts +0 -20
  119. package/template-mobile-vant-cli/src/router/typings.ts +0 -8
  120. package/template-mobile-vant-cli/src/settings/index.ts +0 -10
  121. package/template-mobile-vant-cli/src/utils/crypto/base64.ts +0 -101
  122. package/template-mobile-vant-cli/types/ant-design-import.d.ts +0 -13
  123. package/template-mobile-vant-cli/types/plugins-auto-import.d.ts +0 -14
  124. /package/template-mobile-vant-cli/{mock/datasSource/api/index.ts → src/design/vant/index.less} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gx-design-vue/create-gx-cli",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "a cli to bootstrap gx project",
package/src/cli.js CHANGED
@@ -1,12 +1,15 @@
1
1
  import chalk from 'chalk'
2
2
  import fs from 'node:fs'
3
+ import { fileURLToPath } from 'node:url'
3
4
  import path from 'node:path'
4
5
  import minimist from 'minimist'
5
6
  import prompts from 'prompts'
6
7
  import { blue, green, red, reset, yellow } from 'kolorist'
7
8
  import { createProject } from './main.js'
8
9
 
9
- let packageJSON = fs.readFileSync(path.join('../package.json'), 'utf-8')
10
+ const __filename = fileURLToPath(import.meta.url)
11
+ const __dirname = path.dirname(__filename)
12
+ let packageJSON = fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8')
10
13
  packageJSON = JSON.parse(packageJSON)
11
14
  const { version } = packageJSON
12
15
 
@@ -32,7 +35,7 @@ const FRAMEWORKS = [
32
35
  ]
33
36
 
34
37
  const TEMPLATES = FRAMEWORKS.map(
35
- f => (f.variants && f.variants.map(v => v.name)) || [f.name]
38
+ f => (f.variants && f.variants.map(v => v.name)) || [ f.name ]
36
39
  ).reduce((a, b) => a.concat(b), [])
37
40
 
38
41
  function formatTargetDir(targetDir) {
@@ -40,7 +43,7 @@ function formatTargetDir(targetDir) {
40
43
  }
41
44
 
42
45
  function parseArgumentsIntoOptions() {
43
- const argv = minimist(process.argv.slice(2), { string: ['_'] })
46
+ const argv = minimist(process.argv.slice(2), { string: [ '_' ] })
44
47
  const argTargetDir = formatTargetDir(argv._[0])
45
48
  const argTemplate = argv.template || argv.t
46
49
  return {
@@ -100,7 +103,7 @@ async function promptForMissingOptions(options) {
100
103
  export async function cli() {
101
104
  let options = parseArgumentsIntoOptions()
102
105
  if (options.v) {
103
- console.log(chalk.whiteBright(version))
106
+ console.log(chalk.blueBright(version))
104
107
  process.exit(1)
105
108
  }
106
109
  options = await promptForMissingOptions(options)
package/src/main.js CHANGED
@@ -1,13 +1,13 @@
1
- import chalk from 'chalk'
2
1
  import fs from 'node:fs'
3
- import { reset } from 'kolorist'
4
- import prompts from 'prompts'
5
- import { fileURLToPath } from 'node:url'
6
- import Listr from 'listr'
7
- import ncp from 'ncp'
8
2
  import path from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
9
4
  import { promisify } from 'node:util'
5
+ import chalk from 'chalk'
6
+ import { reset } from 'kolorist'
7
+ import Listr from 'listr'
10
8
  import { createSpinner } from 'nanospinner'
9
+ import ncp from 'ncp'
10
+ import prompts from 'prompts'
11
11
  import { clone } from './git.js'
12
12
 
13
13
  const copy = promisify(ncp)
@@ -102,7 +102,7 @@ function download(url, root, projectName) {
102
102
  text: '项目创建成功,请依次执行以下命令'
103
103
  })
104
104
  doneLog(process.cwd(), root)
105
- }, async function (err) {
105
+ }, async (err) => {
106
106
  console.log(err)
107
107
  spinner.error({ text: '下载失败' })
108
108
  })
@@ -0,0 +1,3 @@
1
+ VITE_IP_ADRESS=101.200.182.125
2
+ VITE_HOME_PAGE=http://101.200.182.125/
3
+ VITE_UPLOAD_PATH=api/prod-api
@@ -4,16 +4,14 @@ VITE_NODE_ENV= development
4
4
  # environment 代码环境
5
5
  VITE_USE_MODE = development
6
6
 
7
- VITE_USE_CDN= false
8
-
9
7
  # 是否开启mock
10
8
  VITE_USE_MOCK = true
11
9
 
12
- # 是否使用v-console
13
- VITE_USE_V_CONSOLE = false
14
-
15
10
  # 是否删除console
16
11
  VITE_DROP_CONSOLE = false
17
12
 
13
+ # proxy 代理的api 前缀
14
+ VITE_PROXY_PREFIX = /devApi
15
+
18
16
  # api前缀
19
- VITE_BASE_URL=/mock-server
17
+ VITE_BASE_URL=/api/prod-api
@@ -4,16 +4,25 @@ VITE_NODE_ENV= production
4
4
  # environment 代码环境
5
5
  VITE_USE_MODE = pro
6
6
 
7
- VITE_USE_CDN= false
8
-
9
- # 是否使用v-console
10
- VITE_USE_V_CONSOLE = false
11
-
12
7
  # 是否开启mock
13
8
  VITE_USE_MOCK = false
14
9
 
15
10
  # 是否删除console
16
- VITE_DROP_CONSOLE = true
11
+ VITE_DROP_CONSOLE = false
12
+
13
+ # Whether to enable gzip or brotli compression
14
+ # Optional: gzip | brotli | none
15
+ # If you need multiple forms, you can use `,` to separate
16
+ VITE_BUILD_COMPRESS = 'none'
17
+
18
+ # 使用压缩时是否删除源文件,默认为false
19
+ VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false
20
+
21
+ # 是否为打包后的文件提供传统浏览器兼容性支持
22
+ VITE_LEGACY = false
23
+
24
+ # proxy 代理的api 前缀
25
+ VITE_PROXY_PREFIX = /proApi
17
26
 
18
27
  # api前缀
19
- VITE_BASE_URL=/mock-server
28
+ VITE_BASE_URL=/api/prod-api
@@ -1,19 +1,31 @@
1
- # 实际执行环境 production
1
+ # 项目启动执行环境
2
2
  VITE_NODE_ENV= production
3
3
 
4
- # environment 代码环境
4
+ # 代码运行环境
5
5
  VITE_USE_MODE = production
6
6
 
7
- VITE_USE_CDN= false
7
+ # 是否开启mock
8
+ VITE_USE_MOCK = false
9
+
10
+ # 是否删除console
11
+ VITE_DROP_CONSOLE = false
12
+
13
+ # Whether to enable gzip or brotli compression
14
+ # Optional: gzip | brotli | none
15
+ # If you need multiple forms, you can use `,` to separate
16
+ VITE_BUILD_COMPRESS = 'none'
8
17
 
9
- # 是否使用v-console
18
+ # 使用压缩时是否删除源文件,默认为false
19
+ VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false
20
+
21
+ # 是否使用vconsole
10
22
  VITE_USE_V_CONSOLE = true
11
23
 
12
- # 是否开启mock
13
- VITE_USE_MOCK = true
24
+ # 是否为打包后的文件提供传统浏览器兼容性支持
25
+ VITE_LEGACY = false
14
26
 
15
- # 是否删除console
16
- VITE_DROP_CONSOLE = true
27
+ # proxy 代理的api 前缀
28
+ VITE_PROXY_PREFIX = /devApi
17
29
 
18
30
  # api前缀
19
- VITE_BASE_URL=/mock-server
31
+ VITE_BASE_URL=/api/prod-api
@@ -0,0 +1,32 @@
1
+ module.exports = {
2
+ ignores: [commit => commit.includes('init')],
3
+ extends: ['@commitlint/config-conventional'],
4
+ rules: {
5
+ 'body-leading-blank': [2, 'always'],
6
+ 'footer-leading-blank': [1, 'always'],
7
+ 'header-max-length': [2, 'always', 108],
8
+ 'subject-empty': [2, 'never'],
9
+ 'type-empty': [2, 'never'],
10
+ 'type-enum': [
11
+ 2,
12
+ 'always',
13
+ [
14
+ 'feat',
15
+ 'fix',
16
+ 'perf',
17
+ 'style',
18
+ 'docs',
19
+ 'test',
20
+ 'refactor',
21
+ 'build',
22
+ 'ci',
23
+ 'chore',
24
+ 'revert',
25
+ 'wip',
26
+ 'workflow',
27
+ 'types',
28
+ 'release',
29
+ ],
30
+ ],
31
+ },
32
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @description 导出默认通用配置
3
+ */
4
+ const settingConfig: SettingConfig = {
5
+ system: {
6
+ // 标题 (包括初次加载雪花屏的标题 页面的标题 浏览器的标题)
7
+ title: 'Gx Vant Mobile',
8
+ // 短标题
9
+ shortName: 'gx_vant_mobile',
10
+ // 标题分隔符
11
+ titleSeparator: ' - ',
12
+ // 标题是否反转 如果为false:"page - title",如果为ture:"title - page"
13
+ titleReverse: false,
14
+ // 是否初始化loading加载
15
+ appInit: {
16
+ loading: {
17
+ text: '资源加载中...'
18
+ }
19
+ },
20
+ // 路由模式,可选值为 browser 或 hash
21
+ routerMode: 'hash',
22
+ // 不经过token校验的路由
23
+ routesWhiteList: [ '/user/login', '/user/register' ],
24
+ // 是否开启登录拦截
25
+ loginInterception: true,
26
+ // 是否开启登录RSA加密
27
+ loginRSA: false
28
+ },
29
+ servive: {
30
+ // 开发环境端口号
31
+ port: 3000,
32
+ },
33
+ build: {
34
+ // 开发以及部署时的URL,hash模式时在不确定二级目录名称的情况下建议使用""代表相对路径或者"/二级目录/",history模式默认使用"/"或者"/二级目录/"
35
+ publicPath: './',
36
+ // 生产环境构建文件的目录名
37
+ outputDir: 'dist',
38
+ // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。
39
+ assetsDir: 'static',
40
+ },
41
+ cdn: {
42
+ // 开启cdn
43
+ use: false,
44
+ // cdn 地址
45
+ url: 'https://cdn.bootcdn.net/ajax/libs/{name}/{version}/{path}',
46
+ // 模块集合
47
+ modules: []
48
+ },
49
+ // proxy 配置
50
+ proxy: {
51
+ // 是否开启代理
52
+ use: true,
53
+ // 代理的目标地址
54
+ target: 'http://127.0.0.1:3000',
55
+ },
56
+ mock: {
57
+ prefix: '/mock-server',
58
+ checkToken: 0,
59
+ },
60
+ token: {
61
+ // token名称
62
+ name: 'Authorization',
63
+ // token在localStorage、sessionStorage、cookie存储的key的名称
64
+ storageName: 'accessToken',
65
+ // token存储位置localStorage sessionStorage cookie
66
+ storage: 'localStorage',
67
+ },
68
+ }
69
+
70
+ export default settingConfig
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description 导出默认网路配置
3
+ */
4
+ const networkSetting: NetworkConfig = {
5
+ // 最长请求时间
6
+ requestTimeout: 10000,
7
+ // 操作正常code,支持String、Array、Number多种类型
8
+ successCode: [ 200, 0 ]
9
+ }
10
+ export default networkSetting
@@ -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
+ }
@@ -2,13 +2,12 @@ import antFuEslint from '@antfu/eslint-config'
2
2
 
3
3
  export default antFuEslint({
4
4
  vue: true,
5
- vueJsx: false,
5
+ vueJsx: true,
6
6
  typescript: true,
7
7
  gitignore: true,
8
8
  markdown: true,
9
9
  ignores: [
10
10
  'src/assets/**/*.js',
11
- 'build/plugin/viteMock',
12
11
  'public',
13
12
  'tsconfig.*.json',
14
13
  'tsconfig.json'
@@ -16,7 +15,14 @@ export default antFuEslint({
16
15
  }, {
17
16
  rules: {
18
17
  'curly': 0,
18
+ 'vue/eqeqeq': 0,
19
19
  'no-console': 0,
20
+ 'vue/no-unused-refs': 0,
21
+ 'no-template-curly-in-string': 0,
22
+ 'vue/prop-name-casing': 0,
23
+ 'vue/html-comment-content-spacing': 0,
24
+ 'style/indent-binary-ops': 0,
25
+ 'antfu/if-newline': 0,
20
26
  'import/order': 0,
21
27
  'style/quote-props': 0,
22
28
  'style/brace-style': 0,
@@ -40,6 +46,8 @@ export default antFuEslint({
40
46
  'eslint-comments/no-unlimited-disable': 0,
41
47
  'no-async-promise-executor': 0,
42
48
  'unicorn/escape-case': 0,
49
+ 'ts/ban-ts-comment': 0,
50
+ 'ts/prefer-ts-expect-error': 0,
43
51
  'ts/method-signature-style': 0,
44
52
  'style/no-trailing-spaces': 0,
45
53
  'ts/consistent-type-imports': 0,
@@ -1,24 +1,25 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="zh">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" href="/favicon.ico" type="image/x-icon" />
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-vant-mobile</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"></div>
17
- <% for (var i in injectScript) { %>
18
- <script type="text/javascript" src="<%= injectScript[i] %>"></script>
19
- <% } %>
20
- <script type="module" src="/src/main.ts"></script>
21
- <%- injectVlogScript %>
22
- <script src="/js/flexible.js"></script>
23
- </body>
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>
24
25
  </html>
@@ -1,4 +1,4 @@
1
- import { resolve } from 'path'
1
+ import { resolve } from 'node:path'
2
2
 
3
3
  export function generateModifyVars() {
4
4
  return {
@@ -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
+ }