create-young-proj 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +11 -2
- package/dist/index.mjs +2702 -42
- package/package.json +3 -3
- package/template-admin-server/package.json +2 -2
- package/template-vue-admin/build/custom-plugin.ts +30 -0
- package/template-vue-admin/build/index.ts +7 -0
- package/template-vue-admin/build/plugins.ts +59 -0
- package/template-vue-admin/package.json +1 -1
- package/template-vue-admin/src/main.ts +4 -4
- package/template-vue-admin/src/modules/4-auth.ts +8 -4
- package/template-vue-admin/src/shims.d.ts +12 -0
- package/template-vue-admin/tsconfig.node.json +1 -1
- package/template-vue-admin/vite.config.ts +4 -49
- package/template-vue-mobile/.vscode/base.code-snippets +24 -0
- package/template-vue-mobile/.vscode/extensions.json +10 -0
- package/template-vue-mobile/.vscode/settings.json +7 -0
- package/template-vue-mobile/Dockerfile +42 -0
- package/template-vue-mobile/README.md +71 -0
- package/template-vue-mobile/_env +6 -0
- package/template-vue-mobile/_gitignore +30 -0
- package/template-vue-mobile/boot.mjs +16 -0
- package/template-vue-mobile/build/custom-plugin.ts +30 -0
- package/template-vue-mobile/build/index.ts +7 -0
- package/template-vue-mobile/build/plugins.ts +68 -0
- package/template-vue-mobile/config/.devrc +2 -0
- package/template-vue-mobile/config/.onlinerc +1 -0
- package/template-vue-mobile/config/.testrc +1 -0
- package/template-vue-mobile/index.html +25 -0
- package/template-vue-mobile/nitro.config.ts +19 -0
- package/template-vue-mobile/package.json +48 -0
- package/template-vue-mobile/plugins/env.ts +26 -0
- package/template-vue-mobile/public/vite.svg +1 -0
- package/template-vue-mobile/rome.json +24 -0
- package/template-vue-mobile/routes/[...all].ts +11 -0
- package/template-vue-mobile/routes/get/env.ts +25 -0
- package/template-vue-mobile/src/App.vue +29 -0
- package/template-vue-mobile/src/auto-components.d.ts +24 -0
- package/template-vue-mobile/src/auto-imports.d.ts +289 -0
- package/template-vue-mobile/src/components/Init.vue +36 -0
- package/template-vue-mobile/src/global.d.ts +7 -0
- package/template-vue-mobile/src/hooks/useVerifyCode.ts +46 -0
- package/template-vue-mobile/src/layouts/blank.vue +9 -0
- package/template-vue-mobile/src/layouts/default.vue +27 -0
- package/template-vue-mobile/src/layouts/sub.vue +20 -0
- package/template-vue-mobile/src/main.ts +35 -0
- package/template-vue-mobile/src/modules/1-router.ts +40 -0
- package/template-vue-mobile/src/modules/2-pinia.ts +10 -0
- package/template-vue-mobile/src/modules/3-net.ts +46 -0
- package/template-vue-mobile/src/modules/4-auth.ts +64 -0
- package/template-vue-mobile/src/views/[...all_404].vue +557 -0
- package/template-vue-mobile/src/views/base/login.vue +110 -0
- package/template-vue-mobile/src/views/base/resetPasswd.vue +88 -0
- package/template-vue-mobile/src/views/index.vue +18 -0
- package/template-vue-mobile/src/views/my.vue +15 -0
- package/template-vue-mobile/src/views/sub.vue +18 -0
- package/template-vue-mobile/src/vite-env.d.ts +43 -0
- package/template-vue-mobile/tsconfig.json +21 -0
- package/template-vue-mobile/tsconfig.node.json +9 -0
- package/template-vue-mobile/unocss.config.ts +47 -0
- package/template-vue-mobile/vite.config.ts +32 -0
- package/template-vue-mobile/yarn.lock +4395 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "create-young-proj",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.2.0",
|
4
4
|
"description": "create project from template",
|
5
5
|
"main": "index.mjs",
|
6
6
|
"bin": {
|
@@ -45,8 +45,8 @@
|
|
45
45
|
"scripts": {
|
46
46
|
"dev": "unbuild --stub",
|
47
47
|
"build": "unbuild",
|
48
|
-
"format": "rome format
|
49
|
-
"release": "changelogen && bumpp --
|
48
|
+
"format": "rome format . --write",
|
49
|
+
"release": "changelogen && bumpp --no-push",
|
50
50
|
"push": "pnpm publish --access public"
|
51
51
|
}
|
52
52
|
}
|
@@ -45,7 +45,7 @@
|
|
45
45
|
"start": "cross-env NODE_ENV=production node ./boot.mjs",
|
46
46
|
"dev": "cross-env NODE_ENV=local midway-bin dev --ts",
|
47
47
|
"build": "midway-bin build -c",
|
48
|
-
"format": "rome format
|
48
|
+
"format": "rome format * --write"
|
49
49
|
},
|
50
50
|
"midway-bin-clean": [
|
51
51
|
".vscode/.tsbuildinfo",
|
@@ -57,4 +57,4 @@
|
|
57
57
|
},
|
58
58
|
"author": "BluesYoung-web",
|
59
59
|
"license": "MIT"
|
60
|
-
}
|
60
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-01-10 14:43:13
|
4
|
+
* @LastEditTime: 2023-01-10 15:11:44
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import { networkInterfaces } from 'node:os';
|
8
|
+
|
9
|
+
const virtualModuleId = 'virtual:local-server';
|
10
|
+
const ips = networkInterfaces();
|
11
|
+
export const localServer = `http://${ips['eth0'][0].address}:3000`;
|
12
|
+
|
13
|
+
/**
|
14
|
+
* 获取本机 ip 地址,拼接开发时的服务地址
|
15
|
+
*/
|
16
|
+
export const serverPlugin = () => {
|
17
|
+
return {
|
18
|
+
name: 'local-server',
|
19
|
+
resolveId(id) {
|
20
|
+
if (id === virtualModuleId) {
|
21
|
+
return virtualModuleId;
|
22
|
+
}
|
23
|
+
},
|
24
|
+
load(id) {
|
25
|
+
if (id === virtualModuleId) {
|
26
|
+
return `export const server = '${localServer}';`;
|
27
|
+
}
|
28
|
+
},
|
29
|
+
};
|
30
|
+
};
|
@@ -0,0 +1,59 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-01-10 14:26:01
|
4
|
+
* @LastEditTime: 2023-01-10 15:18:31
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import type { PluginOption } from 'vite';
|
8
|
+
import { serverPlugin } from './custom-plugin';
|
9
|
+
import vue from '@vitejs/plugin-vue';
|
10
|
+
import vueJsx from '@vitejs/plugin-vue-jsx';
|
11
|
+
import legacy from '@vitejs/plugin-legacy';
|
12
|
+
import Unocss from 'unocss/vite';
|
13
|
+
// 自动导入
|
14
|
+
import AutoImport from 'unplugin-auto-import/vite';
|
15
|
+
import AutoComopnents from 'unplugin-vue-components/vite';
|
16
|
+
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
|
17
|
+
// 自动路由及布局
|
18
|
+
import Pages from 'vite-plugin-pages';
|
19
|
+
import Layouts from 'vite-plugin-vue-layouts';
|
20
|
+
|
21
|
+
export { localServer } from './custom-plugin';
|
22
|
+
|
23
|
+
export const usePlugins = () => {
|
24
|
+
return [
|
25
|
+
serverPlugin(),
|
26
|
+
vue(),
|
27
|
+
vueJsx(),
|
28
|
+
Pages({
|
29
|
+
extensions: ['vue', 'tsx'],
|
30
|
+
dirs: 'src/views',
|
31
|
+
exclude: ['**/components/*.{vue,tsx}', '_*'],
|
32
|
+
}),
|
33
|
+
Layouts({ defaultLayout: 'default/index' }),
|
34
|
+
AutoComopnents({
|
35
|
+
dirs: ['src/components'],
|
36
|
+
dts: './src/auto-components.d.ts',
|
37
|
+
extensions: ['vue', 'tsx'],
|
38
|
+
resolvers: [ElementPlusResolver()],
|
39
|
+
}),
|
40
|
+
AutoImport({
|
41
|
+
dts: './src/auto-imports.d.ts',
|
42
|
+
imports: [
|
43
|
+
'vue',
|
44
|
+
'vue-router',
|
45
|
+
'@vueuse/core',
|
46
|
+
'pinia',
|
47
|
+
{
|
48
|
+
'element-plus': ['ElMessage', 'ElMessageBox', 'ElLoadingService'],
|
49
|
+
},
|
50
|
+
],
|
51
|
+
}),
|
52
|
+
Unocss(),
|
53
|
+
// 不生成同名 polyfill 文件,打包速度翻倍
|
54
|
+
// 如果出现兼容问题,可以删除此配置
|
55
|
+
legacy({
|
56
|
+
// renderLegacyChunks: false
|
57
|
+
}),
|
58
|
+
] as PluginOption[];
|
59
|
+
};
|
@@ -8,7 +8,7 @@
|
|
8
8
|
"dev:server": "nitropack dev",
|
9
9
|
"build": "vite build && nitropack build",
|
10
10
|
"preview": "vite preview --host",
|
11
|
-
"format": "rome format
|
11
|
+
"format": "rome format * --write",
|
12
12
|
"release": "changelogen && bumpp --no-push"
|
13
13
|
},
|
14
14
|
"dependencies": {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* @Author: zhangyang
|
3
3
|
* @Date: 2022-12-03 15:57:40
|
4
|
-
* @LastEditTime: 2023-01-
|
4
|
+
* @LastEditTime: 2023-01-10 15:09:29
|
5
5
|
* @Description:
|
6
6
|
*/
|
7
7
|
// polyfill
|
@@ -13,6 +13,7 @@ import 'uno.css';
|
|
13
13
|
import 'element-plus/dist/index.css';
|
14
14
|
|
15
15
|
import { createApp } from 'vue';
|
16
|
+
import { server } from 'virtual:local-server';
|
16
17
|
import App from './App.vue';
|
17
18
|
|
18
19
|
(async () => {
|
@@ -23,9 +24,8 @@ import App from './App.vue';
|
|
23
24
|
viteEnv = import.meta.env;
|
24
25
|
console.log('🚀 ~ file: main.ts ~ line 19 ~ viteEnv', viteEnv);
|
25
26
|
} else if (import.meta.env.DEV) {
|
26
|
-
//
|
27
|
-
|
28
|
-
viteEnv = await (await fetch(`http://127.0.0.1:3000/get/env`)).json();
|
27
|
+
// 开发环境,局域网 ip
|
28
|
+
viteEnv = await (await fetch(server + '/get/env')).json();
|
29
29
|
console.log('🚀 ~ file: main.ts ~ line 24 ~ viteEnv', viteEnv);
|
30
30
|
} else {
|
31
31
|
// 部署环境,需要配合 nginx 使用
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* @Author: zhangyang
|
3
3
|
* @Date: 2022-03-01 19:40:13
|
4
|
-
* @LastEditTime: 2023-01-
|
4
|
+
* @LastEditTime: 2023-01-11 10:32:35
|
5
5
|
* @Description: 权限校验
|
6
6
|
*/
|
7
7
|
import { router } from './1-router';
|
@@ -84,7 +84,6 @@ export const install: UserModule = (app) => {
|
|
84
84
|
(await casdoorLogin(code, state)) as UserKey;
|
85
85
|
getToken() && (await generateNavData());
|
86
86
|
location.search = '';
|
87
|
-
changeTitle(to);
|
88
87
|
return true;
|
89
88
|
} else
|
90
89
|
*/
|
@@ -99,12 +98,10 @@ export const install: UserModule = (app) => {
|
|
99
98
|
await generateNavData();
|
100
99
|
if (hasPermission(to.meta.authPath)) {
|
101
100
|
// 拥有对应页面的权限
|
102
|
-
changeTitle(to);
|
103
101
|
return true;
|
104
102
|
}
|
105
103
|
if (!hasPermission(to.meta.authPath)) {
|
106
104
|
// 已登录,并且无权限
|
107
|
-
changeTitle(from);
|
108
105
|
return '/403';
|
109
106
|
}
|
110
107
|
} else {
|
@@ -117,6 +114,13 @@ export const install: UserModule = (app) => {
|
|
117
114
|
|
118
115
|
router.afterEach((to) => {
|
119
116
|
const { addView } = useTagsStore();
|
117
|
+
const nav = FlatNavArr.value.find((item) => item.component === to.path);
|
118
|
+
if (nav && nav.title) {
|
119
|
+
// console.log('before: ', to.meta);
|
120
|
+
to.meta.title = nav.title as string;
|
121
|
+
// console.log('after: ', to.meta);
|
122
|
+
}
|
120
123
|
addView(to);
|
124
|
+
changeTitle(to);
|
121
125
|
});
|
122
126
|
};
|
@@ -1,26 +1,13 @@
|
|
1
1
|
/*
|
2
2
|
* @Author: zhangyang
|
3
3
|
* @Date: 2022-12-03 15:57:40
|
4
|
-
* @LastEditTime: 2023-01-
|
4
|
+
* @LastEditTime: 2023-01-10 15:12:20
|
5
5
|
* @Description:
|
6
6
|
*/
|
7
7
|
import { fileURLToPath, URL } from 'node:url';
|
8
8
|
import { defineConfig, loadEnv } from 'vite';
|
9
9
|
import type { ConfigEnv, UserConfigExport } from 'vite';
|
10
|
-
|
11
|
-
import vue from '@vitejs/plugin-vue';
|
12
|
-
import vueJsx from '@vitejs/plugin-vue-jsx';
|
13
|
-
import legacy from '@vitejs/plugin-legacy';
|
14
|
-
import Unocss from 'unocss/vite';
|
15
|
-
|
16
|
-
// 自动导入
|
17
|
-
import AutoImport from 'unplugin-auto-import/vite';
|
18
|
-
import AutoComopnents from 'unplugin-vue-components/vite';
|
19
|
-
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
|
20
|
-
|
21
|
-
// 自动路由及布局
|
22
|
-
import Pages from 'vite-plugin-pages';
|
23
|
-
import Layouts from 'vite-plugin-vue-layouts';
|
10
|
+
import { usePlugins, localServer } from './build';
|
24
11
|
|
25
12
|
// https://vitejs.dev/config/
|
26
13
|
export default ({ command, mode }: ConfigEnv): UserConfigExport => {
|
@@ -29,39 +16,7 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
|
|
29
16
|
console.log('🚀 ~ file: vite.config.ts ~ line 36 ~ viteEnv', viteEnv);
|
30
17
|
return defineConfig({
|
31
18
|
base: './',
|
32
|
-
plugins:
|
33
|
-
vue(),
|
34
|
-
vueJsx(),
|
35
|
-
Pages({
|
36
|
-
extensions: ['vue', 'tsx'],
|
37
|
-
dirs: 'src/views',
|
38
|
-
exclude: ['**/components/*.{vue,tsx}', '_*'],
|
39
|
-
}),
|
40
|
-
Layouts({ defaultLayout: 'default/index' }),
|
41
|
-
AutoComopnents({
|
42
|
-
dirs: ['src/components'],
|
43
|
-
dts: './src/auto-components.d.ts',
|
44
|
-
extensions: ['vue', 'tsx'],
|
45
|
-
resolvers: [ElementPlusResolver()],
|
46
|
-
}),
|
47
|
-
AutoImport({
|
48
|
-
dts: './src/auto-imports.d.ts',
|
49
|
-
imports: [
|
50
|
-
'vue',
|
51
|
-
'vue-router',
|
52
|
-
'@vueuse/core',
|
53
|
-
'pinia',
|
54
|
-
{
|
55
|
-
'element-plus': ['ElMessage', 'ElMessageBox', 'ElLoadingService'],
|
56
|
-
},
|
57
|
-
],
|
58
|
-
}),
|
59
|
-
Unocss(),
|
60
|
-
legacy({
|
61
|
-
// 不生成同名 polyfill 文件,打包速度翻倍,如果出现兼容问题,可以删除此配置
|
62
|
-
// renderLegacyChunks: false
|
63
|
-
}),
|
64
|
-
],
|
19
|
+
plugins: usePlugins(),
|
65
20
|
resolve: {
|
66
21
|
alias: {
|
67
22
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
@@ -70,7 +25,7 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
|
|
70
25
|
server: {
|
71
26
|
host: true,
|
72
27
|
proxy: {
|
73
|
-
'/api':
|
28
|
+
'/api': localServer,
|
74
29
|
},
|
75
30
|
},
|
76
31
|
});
|
@@ -0,0 +1,24 @@
|
|
1
|
+
{
|
2
|
+
"mobile base": {
|
3
|
+
"prefix": "base",
|
4
|
+
"body": [
|
5
|
+
"<route lang=\"yaml\">",
|
6
|
+
"meta:",
|
7
|
+
" auth: true",
|
8
|
+
" title: $1",
|
9
|
+
" layout: sub",
|
10
|
+
"</route>",
|
11
|
+
"",
|
12
|
+
"<script lang=\"ts\" setup>",
|
13
|
+
"$2",
|
14
|
+
"</script>",
|
15
|
+
"",
|
16
|
+
"<template>",
|
17
|
+
" <div>",
|
18
|
+
" $1",
|
19
|
+
" </div>",
|
20
|
+
"</template>",
|
21
|
+
],
|
22
|
+
"description": "mobile base"
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# 拉取基础镜像
|
2
|
+
FROM node:16-alpine as builder
|
3
|
+
|
4
|
+
# 维护者
|
5
|
+
MAINTAINER BluesYoung "bluesyoung_web@163.com"
|
6
|
+
|
7
|
+
# 工作目录
|
8
|
+
WORKDIR /app
|
9
|
+
|
10
|
+
# 没有压缩包,首选 COPY,如果需要自动解包或下载,则使用 ADD
|
11
|
+
|
12
|
+
# 对比依赖是否变更
|
13
|
+
COPY package.json yarn.lock /app/
|
14
|
+
|
15
|
+
# 设置npm仓库 + 下载依赖,上面的文件如果没有变化则跳过下载,直接使用缓存
|
16
|
+
RUN npm config set registry https://registry.npmmirror.com && \
|
17
|
+
yarn config set registry https://registry.npmmirror.com && \
|
18
|
+
yarn
|
19
|
+
|
20
|
+
# 加入代码
|
21
|
+
COPY . /app
|
22
|
+
# 打包
|
23
|
+
RUN yarn build
|
24
|
+
|
25
|
+
# 打包完成,构建最终的极简镜像
|
26
|
+
FROM node:16-alpine
|
27
|
+
|
28
|
+
# 工作目录
|
29
|
+
WORKDIR /app
|
30
|
+
|
31
|
+
# 复制运行需要的文件[及依赖]
|
32
|
+
# 直接复制源代码
|
33
|
+
COPY boot.mjs /app/
|
34
|
+
COPY config /app/config
|
35
|
+
# 复制上一步的打包产物
|
36
|
+
COPY --from=builder /app/.output /app/.output
|
37
|
+
|
38
|
+
# 暴露指定的端口号,暂不需要
|
39
|
+
# EXPOSE 3001
|
40
|
+
|
41
|
+
# 启动容器时运行的命令
|
42
|
+
ENTRYPOINT ["node", "boot.mjs"]
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# h5 模板
|
2
|
+
|
3
|
+
## 用户代码片段(页面模板)
|
4
|
+
|
5
|
+
模板 | 触发关键字
|
6
|
+
--- | ---
|
7
|
+
基础页面 | `base`
|
8
|
+
|
9
|
+
## **Docker 部署**
|
10
|
+
|
11
|
+
- 同一份代码,可以根据运行时的环境变量决定具体表现
|
12
|
+
- `node` 服务:
|
13
|
+
- 托管前端静态资源
|
14
|
+
- 根据环境变量读取对应的配置文件,并以接口的形式暴露给前端
|
15
|
+
- 跨域接口代理
|
16
|
+
|
17
|
+
环境变量
|
18
|
+
|
19
|
+
```sh
|
20
|
+
# 部署环境 dev | test | online
|
21
|
+
DEPLOY_ENV=dev
|
22
|
+
# DEPLOY_ENV=test
|
23
|
+
# DEPLOY_ENV=online
|
24
|
+
# node 服务监听的端口号
|
25
|
+
LISTEN_PORT=3000
|
26
|
+
```
|
27
|
+
|
28
|
+
### 本地开发
|
29
|
+
|
30
|
+
**确保上述的环境变量存在**
|
31
|
+
|
32
|
+
启动服务端程序 `yarn dev:server`
|
33
|
+
|
34
|
+
启动客户端程序 `yarn dev`
|
35
|
+
|
36
|
+
### 打包预览
|
37
|
+
|
38
|
+
`yarn build`
|
39
|
+
|
40
|
+
**确保上述的环境变量存在!!!**
|
41
|
+
|
42
|
+
`node boot.mjs`
|
43
|
+
|
44
|
+
### 配置文件
|
45
|
+
|
46
|
+
存放于 `config` 目录下的 `.${env}rc` 文件,`env` 为对应的环境标识
|
47
|
+
|
48
|
+
## 常规部署
|
49
|
+
|
50
|
+
- `nginx` 托管前端静态资源
|
51
|
+
- 每次打包时读取环境变量,打包完成之后不可变
|
52
|
+
- 使用 `nginx` 代理跨域
|
53
|
+
|
54
|
+
环境变量
|
55
|
+
|
56
|
+
```sh
|
57
|
+
# 设置静态部署
|
58
|
+
VITE_USE_DEFAULT_DEPLOY_METHOD=true
|
59
|
+
# 其他的环境变量,根据环境区分
|
60
|
+
VITE_TITLE=标题名称
|
61
|
+
```
|
62
|
+
|
63
|
+
### 本地开发
|
64
|
+
|
65
|
+
**确保上述的环境变量存在**,然后 `yarn dev` 即可
|
66
|
+
|
67
|
+
### 打包预览
|
68
|
+
|
69
|
+
`yarn build`
|
70
|
+
|
71
|
+
`yarn preview`
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Logs
|
2
|
+
logs
|
3
|
+
*.log
|
4
|
+
npm-debug.log*
|
5
|
+
yarn-debug.log*
|
6
|
+
yarn-error.log*
|
7
|
+
pnpm-debug.log*
|
8
|
+
lerna-debug.log*
|
9
|
+
|
10
|
+
node_modules
|
11
|
+
dist
|
12
|
+
dist-ssr
|
13
|
+
*.local
|
14
|
+
.env
|
15
|
+
|
16
|
+
# Editor directories and files
|
17
|
+
.vscode/*
|
18
|
+
!.vscode/extensions.json
|
19
|
+
!.vscode/settings.json
|
20
|
+
!.vscode/*.code-snippets
|
21
|
+
.idea
|
22
|
+
.DS_Store
|
23
|
+
*.suo
|
24
|
+
*.ntvs*
|
25
|
+
*.njsproj
|
26
|
+
*.sln
|
27
|
+
*.sw?
|
28
|
+
|
29
|
+
.nitro
|
30
|
+
.output
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2022-09-16 11:48:05
|
4
|
+
* @LastEditTime: 2022-12-29 16:21:59
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
(async () => {
|
8
|
+
const env = process.env.DEPLOY_ENV;
|
9
|
+
const listenPort = process.env.LISTEN_PORT || 3003;
|
10
|
+
console.log('当前环境:', env);
|
11
|
+
console.log('服务监听端口:', listenPort);
|
12
|
+
|
13
|
+
process.env.NITRO_PORT = listenPort;
|
14
|
+
|
15
|
+
await import('./.output/server/index.mjs');
|
16
|
+
})();
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-01-10 14:43:13
|
4
|
+
* @LastEditTime: 2023-01-10 15:11:44
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import { networkInterfaces } from 'node:os';
|
8
|
+
|
9
|
+
const virtualModuleId = 'virtual:local-server';
|
10
|
+
const ips = networkInterfaces();
|
11
|
+
export const localServer = `http://${ips['eth0'][0].address}:3000`;
|
12
|
+
|
13
|
+
/**
|
14
|
+
* 获取本机 ip 地址,拼接开发时的服务地址
|
15
|
+
*/
|
16
|
+
export const serverPlugin = () => {
|
17
|
+
return {
|
18
|
+
name: 'local-server',
|
19
|
+
resolveId(id) {
|
20
|
+
if (id === virtualModuleId) {
|
21
|
+
return virtualModuleId;
|
22
|
+
}
|
23
|
+
},
|
24
|
+
load(id) {
|
25
|
+
if (id === virtualModuleId) {
|
26
|
+
return `export const server = '${localServer}';`;
|
27
|
+
}
|
28
|
+
},
|
29
|
+
};
|
30
|
+
};
|
@@ -0,0 +1,68 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-01-10 14:26:01
|
4
|
+
* @LastEditTime: 2023-01-13 15:54:55
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import type { PluginOption } from 'vite';
|
8
|
+
import { serverPlugin } from './custom-plugin';
|
9
|
+
import vue from '@vitejs/plugin-vue';
|
10
|
+
import vueJsx from '@vitejs/plugin-vue-jsx';
|
11
|
+
import legacy from '@vitejs/plugin-legacy';
|
12
|
+
import Unocss from 'unocss/vite';
|
13
|
+
// 自动导入
|
14
|
+
import AutoImport from 'unplugin-auto-import/vite';
|
15
|
+
import AutoComopnents from 'unplugin-vue-components/vite';
|
16
|
+
import { VantResolver } from 'unplugin-vue-components/resolvers';
|
17
|
+
// 自动路由及布局
|
18
|
+
import Pages from 'vite-plugin-pages';
|
19
|
+
import Layouts from 'vite-plugin-vue-layouts';
|
20
|
+
|
21
|
+
export { localServer } from './custom-plugin';
|
22
|
+
|
23
|
+
export const usePlugins = () => {
|
24
|
+
return [
|
25
|
+
serverPlugin(),
|
26
|
+
vue(),
|
27
|
+
vueJsx(),
|
28
|
+
Pages({
|
29
|
+
extensions: ['vue', 'tsx'],
|
30
|
+
dirs: 'src/views',
|
31
|
+
exclude: ['**/components/*.{vue,tsx}', '_*'],
|
32
|
+
}),
|
33
|
+
Layouts({ defaultLayout: 'default' }),
|
34
|
+
AutoComopnents({
|
35
|
+
dirs: ['src/components'],
|
36
|
+
dts: './src/auto-components.d.ts',
|
37
|
+
extensions: ['vue', 'tsx'],
|
38
|
+
resolvers: [VantResolver()],
|
39
|
+
}),
|
40
|
+
AutoImport({
|
41
|
+
dts: './src/auto-imports.d.ts',
|
42
|
+
imports: [
|
43
|
+
'vue',
|
44
|
+
'vue-router',
|
45
|
+
'@vueuse/core',
|
46
|
+
'pinia',
|
47
|
+
{
|
48
|
+
vant: [
|
49
|
+
'showToast',
|
50
|
+
'showLoadingToast',
|
51
|
+
'showFailToast',
|
52
|
+
'showSuccessToast',
|
53
|
+
'showDialog',
|
54
|
+
'showConfirmDialog',
|
55
|
+
'showImagePreview',
|
56
|
+
'showNotify',
|
57
|
+
],
|
58
|
+
},
|
59
|
+
],
|
60
|
+
}),
|
61
|
+
Unocss(),
|
62
|
+
// 不生成同名 polyfill 文件,打包速度翻倍
|
63
|
+
// 如果出现兼容问题,可以删除此配置
|
64
|
+
legacy({
|
65
|
+
// renderLegacyChunks: false
|
66
|
+
}),
|
67
|
+
] as PluginOption[];
|
68
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
VITE_TITLE = Mobile-online
|
@@ -0,0 +1 @@
|
|
1
|
+
VITE_TITLE = Mobile-test
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="zh-CN">
|
3
|
+
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8" />
|
6
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
7
|
+
<meta id="viewportMeta" name="viewport"
|
8
|
+
content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0,viewport-fit=cover">
|
9
|
+
<title>Vite + Vue + TS</title>
|
10
|
+
<script>
|
11
|
+
// hack globalThis
|
12
|
+
this.globalThis || (this.globalThis = this);
|
13
|
+
window.onerror = function (e) {
|
14
|
+
console.log(e);
|
15
|
+
window.alert('您的浏览器版本过低,请尝试使用其他浏览器或将浏览器升级至最新版本后重试!');
|
16
|
+
}
|
17
|
+
</script>
|
18
|
+
</head>
|
19
|
+
|
20
|
+
<body>
|
21
|
+
<div id="app"></div>
|
22
|
+
<script type="module" src="/src/main.ts"></script>
|
23
|
+
</body>
|
24
|
+
|
25
|
+
</html>
|