@gx-design-vue/create-gx-cli 0.1.15 → 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.
- package/package.json +1 -1
- package/src/main.js +7 -7
- package/template-mobile-vant-cli/.env +3 -0
- package/template-mobile-vant-cli/.env.development +4 -6
- package/template-mobile-vant-cli/.env.pro +16 -7
- package/template-mobile-vant-cli/.env.production +21 -9
- package/template-mobile-vant-cli/commitlint.config.cjs +32 -0
- package/template-mobile-vant-cli/config/default/defaultSettings.ts +70 -0
- package/template-mobile-vant-cli/config/default/network.ts +10 -0
- package/template-mobile-vant-cli/config/default/proxy.ts +50 -0
- package/template-mobile-vant-cli/config/default/theme.ts +3 -0
- package/template-mobile-vant-cli/config/index.ts +11 -0
- package/template-mobile-vant-cli/eslint.config.js +10 -2
- package/template-mobile-vant-cli/index.html +22 -21
- package/template-mobile-vant-cli/{build → internal/vite-config/generate}/generateModifyVars.ts +1 -1
- package/template-mobile-vant-cli/internal/vite-config/rollupOptions/index.ts +22 -0
- package/template-mobile-vant-cli/internal/vite-config/util/hash.ts +17 -0
- package/template-mobile-vant-cli/internal/vite-config/util/index.ts +132 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/cdn.ts +65 -0
- package/template-mobile-vant-cli/{build → internal/vite-config/vite}/optimizer.ts +9 -1
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/appConfig.ts +91 -0
- package/template-mobile-vant-cli/{build → internal/vite-config/vite}/plugin/autoImport.ts +7 -3
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/compress.ts +31 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/html.ts +32 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/index.ts +74 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/visualizer.ts +14 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/viteNotice.ts +40 -0
- package/template-mobile-vant-cli/mock/config/permissions.ts +15 -0
- package/template-mobile-vant-cli/mock/config/user/id.ts +5 -0
- package/template-mobile-vant-cli/mock/config/user/index.ts +96 -0
- package/template-mobile-vant-cli/mock/index.ts +55 -0
- package/template-mobile-vant-cli/mock/routers/table/index.fake.ts +22 -0
- package/template-mobile-vant-cli/mock/routers/user/account.fake.ts +52 -0
- package/template-mobile-vant-cli/mock/routers/user/index.fake.ts +46 -0
- package/template-mobile-vant-cli/mock/utils/crypto.ts +21 -0
- package/template-mobile-vant-cli/mock/utils/table.ts +96 -0
- package/template-mobile-vant-cli/mock/utils/util.ts +91 -0
- package/template-mobile-vant-cli/package.json +51 -34
- package/template-mobile-vant-cli/public/css/default.css +54 -0
- package/template-mobile-vant-cli/src/App.vue +6 -2
- package/template-mobile-vant-cli/src/assets/logo.png +0 -0
- package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +1 -1
- package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +108 -16
- package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +5 -2
- package/template-mobile-vant-cli/src/components/TabsMenu/index.vue +45 -0
- package/template-mobile-vant-cli/src/core/gx-design/index.ts +1 -1
- package/template-mobile-vant-cli/src/core/index.ts +0 -7
- package/template-mobile-vant-cli/src/design/color.less +1 -0
- package/template-mobile-vant-cli/src/design/config.less +5 -0
- package/template-mobile-vant-cli/src/design/index.less +1 -1
- package/template-mobile-vant-cli/src/design/mixin.less +65 -0
- package/template-mobile-vant-cli/src/design/reset.less +16 -132
- package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +7 -9
- package/template-mobile-vant-cli/src/layout/{BasicLayout.vue → BasicLayout/index.vue} +3 -1
- package/template-mobile-vant-cli/src/layout/BasicLayout/style.less +3 -0
- package/template-mobile-vant-cli/src/layout/UserLayout/index.vue +18 -0
- package/template-mobile-vant-cli/src/layout/UserLayout/style.module.less +36 -0
- package/template-mobile-vant-cli/src/main.ts +16 -9
- package/template-mobile-vant-cli/src/pages/Account/details.vue +13 -0
- package/template-mobile-vant-cli/src/pages/Account/index.vue +102 -0
- package/template-mobile-vant-cli/src/pages/{home.vue → Home/index.vue} +5 -5
- package/template-mobile-vant-cli/src/pages/user/login/index.vue +74 -0
- package/template-mobile-vant-cli/src/plugins/dayjs/index.ts +3 -0
- package/template-mobile-vant-cli/src/plugins/index.ts +2 -0
- package/template-mobile-vant-cli/src/router/guard/index.ts +18 -0
- package/template-mobile-vant-cli/src/router/guard/permissions.ts +41 -0
- package/template-mobile-vant-cli/src/router/guard/stateGuard.ts +10 -0
- package/template-mobile-vant-cli/src/router/index.ts +21 -15
- package/template-mobile-vant-cli/src/router/routes/index.ts +46 -0
- package/template-mobile-vant-cli/src/router/routes/modules/dataSource.ts +32 -0
- package/template-mobile-vant-cli/src/services/userCenter/account.ts +42 -0
- package/template-mobile-vant-cli/src/services/userCenter/index.ts +28 -0
- package/template-mobile-vant-cli/src/store/index.ts +4 -1
- package/template-mobile-vant-cli/src/store/modules/global.ts +6 -13
- package/template-mobile-vant-cli/src/store/modules/user.ts +107 -0
- package/template-mobile-vant-cli/src/utils/accessToken.ts +97 -0
- package/template-mobile-vant-cli/src/utils/crypto/index.ts +3 -4
- package/template-mobile-vant-cli/src/utils/env.ts +2 -2
- package/template-mobile-vant-cli/src/utils/pageTitle.ts +12 -6
- package/template-mobile-vant-cli/src/utils/request/XHR.ts +9 -11
- package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +5 -5
- package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +18 -2
- package/template-mobile-vant-cli/src/utils/request/index.ts +36 -23
- package/template-mobile-vant-cli/src/utils/storage.ts +49 -32
- package/template-mobile-vant-cli/src/utils/validate.ts +31 -36
- package/template-mobile-vant-cli/tsconfig.json +17 -9
- package/template-mobile-vant-cli/types/auto-imports.d.ts +18 -2
- package/template-mobile-vant-cli/types/components.d.ts +2 -7
- package/template-mobile-vant-cli/types/config.d.ts +56 -0
- package/template-mobile-vant-cli/types/global.d.ts +62 -21
- package/template-mobile-vant-cli/types/mock.d.ts +34 -0
- package/template-mobile-vant-cli/types/module.d.ts +33 -0
- package/template-mobile-vant-cli/types/response.d.ts +3 -1
- package/template-mobile-vant-cli/types/system.d.ts +58 -0
- package/template-mobile-vant-cli/types/vant-import.d.ts +16 -5
- package/template-mobile-vant-cli/unocss.config.ts +120 -66
- package/template-mobile-vant-cli/vite.config.ts +78 -81
- package/template-mobile-vant-cli/build/cdn.ts +0 -5
- package/template-mobile-vant-cli/build/plugin/html.ts +0 -26
- package/template-mobile-vant-cli/build/plugin/index.ts +0 -42
- package/template-mobile-vant-cli/build/plugin/mock.ts +0 -14
- package/template-mobile-vant-cli/build/plugin/viteMock/client.ts +0 -88
- package/template-mobile-vant-cli/build/plugin/viteMock/createMockServer.ts +0 -271
- package/template-mobile-vant-cli/build/plugin/viteMock/index.ts +0 -69
- package/template-mobile-vant-cli/build/plugin/viteMock/types.ts +0 -48
- package/template-mobile-vant-cli/build/plugin/viteMock/utils.ts +0 -48
- package/template-mobile-vant-cli/build/script/postBuild.ts +0 -14
- package/template-mobile-vant-cli/mock/_createProductionServer.ts +0 -19
- package/template-mobile-vant-cli/mock/utils.ts +0 -9
- package/template-mobile-vant-cli/postcss.config.cjs +0 -8
- package/template-mobile-vant-cli/prettier.config.cjs +0 -18
- package/template-mobile-vant-cli/public/js/flexible.js +0 -44
- package/template-mobile-vant-cli/src/core/vant-design/index.ts +0 -4
- package/template-mobile-vant-cli/src/design/vant.less +0 -2
- package/template-mobile-vant-cli/src/global.less +0 -1
- package/template-mobile-vant-cli/src/layout/basicLayout.less +0 -11
- package/template-mobile-vant-cli/src/router/routes.ts +0 -20
- package/template-mobile-vant-cli/src/router/typings.ts +0 -8
- package/template-mobile-vant-cli/src/settings/index.ts +0 -10
- package/template-mobile-vant-cli/src/utils/crypto/base64.ts +0 -101
- package/template-mobile-vant-cli/types/ant-design-import.d.ts +0 -13
- package/template-mobile-vant-cli/types/plugins-auto-import.d.ts +0 -14
- /package/template-mobile-vant-cli/{mock/datasSource/api/index.ts → src/design/vant/index.less} +0 -0
package/package.json
CHANGED
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
|
105
|
+
}, async (err) => {
|
106
106
|
console.log(err)
|
107
107
|
spinner.error({ text: '下载失败' })
|
108
108
|
})
|
@@ -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=/
|
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 =
|
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=/
|
28
|
+
VITE_BASE_URL=/api/prod-api
|
@@ -1,19 +1,31 @@
|
|
1
|
-
#
|
1
|
+
# 项目启动执行环境
|
2
2
|
VITE_NODE_ENV= production
|
3
3
|
|
4
|
-
#
|
4
|
+
# 代码运行环境
|
5
5
|
VITE_USE_MODE = production
|
6
6
|
|
7
|
-
|
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
|
-
#
|
18
|
+
# 使用压缩时是否删除源文件,默认为false
|
19
|
+
VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false
|
20
|
+
|
21
|
+
# 是否使用vconsole
|
10
22
|
VITE_USE_V_CONSOLE = true
|
11
23
|
|
12
|
-
#
|
13
|
-
|
24
|
+
# 是否为打包后的文件提供传统浏览器兼容性支持
|
25
|
+
VITE_LEGACY = false
|
14
26
|
|
15
|
-
#
|
16
|
-
|
27
|
+
# proxy 代理的api 前缀
|
28
|
+
VITE_PROXY_PREFIX = /devApi
|
17
29
|
|
18
30
|
# api前缀
|
19
|
-
VITE_BASE_URL=/
|
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,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
|
+
}
|
@@ -2,13 +2,12 @@ import antFuEslint from '@antfu/eslint-config'
|
|
2
2
|
|
3
3
|
export default antFuEslint({
|
4
4
|
vue: true,
|
5
|
-
vueJsx:
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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>
|
@@ -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()
|
@@ -4,13 +4,21 @@ const vendorLibs: { match: string[]; output: string }[] = [
|
|
4
4
|
{
|
5
5
|
match: ['vant'],
|
6
6
|
output: 'vant',
|
7
|
+
},
|
8
|
+
{
|
9
|
+
match: ['crypto-js'],
|
10
|
+
output: 'crypto-js',
|
11
|
+
},
|
12
|
+
{
|
13
|
+
match: ['lodash-es'],
|
14
|
+
output: 'lodash-es',
|
7
15
|
}
|
8
16
|
]
|
9
17
|
|
10
18
|
export const configManualChunk: GetManualChunk = (id: string) => {
|
11
19
|
if (/[\\/]node_modules[\\/]/.test(id)) {
|
12
20
|
const matchItem = vendorLibs.find((item) => {
|
13
|
-
const reg = new RegExp(`[\\/]node_modules[\\/]_?(${item.match.join('|')})(.*)`, '
|
21
|
+
const reg = new RegExp(`[\\/]node_modules[\\/]_?(${item.match.join('|')})(.*)`, 'gi')
|
14
22
|
return reg.test(id)
|
15
23
|
})
|
16
24
|
return matchItem ? matchItem.output : null
|