@roki-h5/create-roki-app 0.1.8 → 0.1.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roki-h5/create-roki-app",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Roki H5 项目脚手架",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,7 +1,5 @@
1
1
  # just a flag
2
2
  VITE_ENV = 'dev'
3
- # 页面标题(脚手架生成时会替换为项目名)
4
- VITE_APP_TITLE=__PROJECT_NAME__
5
3
  # baseUrl
6
4
  VITE_BASE_API=/api
7
5
  VITE_NORMALDEVICE_BASE_API=/api
@@ -1,9 +1,5 @@
1
- # 相对路径:本地可直接打开 dist/index.html;线上子路径部署改为 VITE_PUBLIC_BASE=/your-app/
2
1
  VITE_PUBLIC_BASE=./
3
- # just a flag
4
2
  VITE_ENV = 'prod'
5
- # 页面标题(脚手架生成时会替换为项目名)
6
- VITE_APP_TITLE=__PROJECT_NAME__
7
- # baseUrl
8
3
  VITE_BASE_API='https://api.myroki.com'
9
4
  VITE_NORMALDEVICE_BASE_API=https://api.myroki.com
5
+
@@ -1,9 +1,5 @@
1
- # 相对路径,产物可本地双击 index.html(勿用于需固定子路径的线上目录)
2
1
  VITE_PUBLIC_BASE=./
3
- # just a flag
4
- VITE_ENV = 'test'
5
- # 页面标题(脚手架生成时会替换为项目名)
6
- VITE_APP_TITLE=__PROJECT_NAME__
7
- # baseUrl
2
+ VITE_ENV = 'test'
8
3
  VITE_BASE_API='http://api-test.myroki.com'
9
4
  VITE_NORMALDEVICE_BASE_API=http://api-test.myroki.com
5
+
@@ -6,5 +6,6 @@ export const appEnv = import.meta.env.VITE_ENV ?? import.meta.env.MODE
6
6
 
7
7
  export const apiBase = import.meta.env.VITE_BASE_API ?? ''
8
8
 
9
+ /** SSE 等长连接 API 根路径,默认同 VITE_BASE_API */
9
10
  export const normalDeviceApiBase =
10
11
  import.meta.env.VITE_NORMALDEVICE_BASE_API ?? apiBase
@@ -12,7 +12,7 @@
12
12
  <meta name="apple-touch-fullscreen" content="yes" />
13
13
  <link rel="icon" type="image/png" href="/favicon.png" />
14
14
  <link rel="icon" href="/favicon.ico" sizes="any" />
15
- <title>%VITE_APP_TITLE%</title>
15
+ <title>Roki H5</title>
16
16
  </head>
17
17
  <body>
18
18
  <div id="app" class="roki-reset"></div>
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "@roki-h5/scaffold-template",
3
3
  "private": true,
4
- "version": "0.1.4",
4
+ "version": "0.1.5",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite --mode development",
8
- "build": "vue-tsc -b && node scripts/version.js && vite build --mode production",
9
- "build:test": "vue-tsc -b && node scripts/version.js && vite build --mode test",
10
- "build:prod": "vite build --mode production",
8
+ "build": "vue-tsc -b && node scripts/version.js && vite build --mode production && node scripts/zip-dist.js",
9
+ "build:test": "vue-tsc -b && node scripts/version.js && vite build --mode test && node scripts/zip-dist.js",
10
+ "build:prod": "vite build --mode production && node scripts/zip-dist.js",
11
11
  "preview": "vite preview",
12
12
  "preview:test": "vite preview --mode test"
13
13
  },
14
14
  "dependencies": {
15
15
  "@roki-h5/ui": "workspace:*",
16
+ "@vitejs/plugin-legacy": "^6.0.0",
16
17
  "axios": "^1.7.9",
17
18
  "event-source-polyfill": "^1.0.31",
18
19
  "pinia": "^2.3.0",
@@ -24,6 +25,7 @@
24
25
  "autoprefixer": "^10.4.20",
25
26
  "postcss": "^8.4.49",
26
27
  "postcss-pxtorem": "^6.1.0",
28
+ "terser": "^5.37.0",
27
29
  "typescript": "^5.7.2",
28
30
  "vite": "^6.0.3",
29
31
  "vue-tsc": "^2.1.10"
@@ -0,0 +1,21 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { execSync } from 'node:child_process'
4
+ import { fileURLToPath } from 'node:url'
5
+
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
7
+ const root = path.resolve(__dirname, '..')
8
+ const distDir = path.join(root, 'dist')
9
+ const zipPath = path.join(root, 'dist.zip')
10
+
11
+ if (!fs.existsSync(distDir)) {
12
+ console.error('[zip-dist] dist 目录不存在,请先执行 vite build')
13
+ process.exit(1)
14
+ }
15
+
16
+ if (fs.existsSync(zipPath)) {
17
+ fs.rmSync(zipPath)
18
+ }
19
+
20
+ execSync('zip -r dist.zip dist', { cwd: root, stdio: 'inherit' })
21
+ console.log(`[zip-dist] 已生成 ${zipPath}`)
@@ -7,7 +7,6 @@ import { useDeviceShadow } from '@/utils/useDeviceShadow'
7
7
  import { useGlobalSse } from '@/utils/useGlobalSse'
8
8
 
9
9
  const appStore = useAppStore()
10
- const appTitle = import.meta.env.VITE_APP_TITLE || 'Roki H5'
11
10
 
12
11
  useDeviceShadow()
13
12
  useGlobalSse()
@@ -20,7 +19,7 @@ onBeforeMount(async () => {
20
19
  function logBuildInfo() {
21
20
  setTimeout(() => {
22
21
  console.log(
23
- `[${appTitle} 版本信息]\n` +
22
+ `[Roki H5 版本信息]\n` +
24
23
  `版本号:v${VERSION}\n` +
25
24
  `构建时间:${BUILD_TIME}`,
26
25
  )
@@ -1,6 +1,9 @@
1
1
  import { createRouter, createWebHashHistory } from 'vue-router'
2
2
  import Home from '@/views/home/index.vue'
3
3
 
4
+ /** 首页 document.title:无设备名时使用 */
5
+ const HOME_TITLE_FALLBACK = '燃气热水器'
6
+
4
7
  const router = createRouter({
5
8
  history: createWebHashHistory(import.meta.env.BASE_URL),
6
9
  routes: [
@@ -8,7 +11,7 @@ const router = createRouter({
8
11
  path: '/',
9
12
  name: 'Home',
10
13
  component: Home,
11
- meta: { title: import.meta.env.VITE_APP_TITLE },
14
+ meta: { title: HOME_TITLE_FALLBACK },
12
15
  },
13
16
  ],
14
17
  scrollBehavior: () => ({ top: 0 }),
@@ -13,7 +13,6 @@ declare module '*.png' {
13
13
 
14
14
  interface ImportMetaEnv {
15
15
  readonly VITE_ENV: string
16
- readonly VITE_APP_TITLE: string
17
16
  readonly VITE_BASE_API: string
18
17
  readonly VITE_NORMALDEVICE_BASE_API: string
19
18
  readonly VITE_PUBLIC_BASE?: string
@@ -1,6 +1,7 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
  import { fileURLToPath } from 'node:url'
4
+ import legacy from '@vitejs/plugin-legacy'
4
5
  import { defineConfig, loadEnv } from 'vite'
5
6
  import vue from '@vitejs/plugin-vue'
6
7
 
@@ -8,9 +9,32 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
8
9
  const monorepoUiDir = path.resolve(__dirname, '../../../ui')
9
10
  const isMonorepoDev = fs.existsSync(path.join(monorepoUiDir, 'package.json'))
10
11
 
12
+ /** file:// 打开 dist 时去掉 crossorigin;legacy-only 时再去掉 modulepreload */
13
+ function distHtmlPostProcess({ removeModulePreload = false } = {}) {
14
+ return {
15
+ name: 'dist-html-post-process',
16
+ apply: 'build' as const,
17
+ enforce: 'post' as const,
18
+ transformIndexHtml(html: string) {
19
+ let out = html.replace(
20
+ /\s+crossorigin(?:=(?:"[^"]*"|'[^']*'|[^\s>]+))?/gi,
21
+ '',
22
+ )
23
+ if (removeModulePreload) {
24
+ out = out.replace(
25
+ /<link[^>]*\srel=["']modulepreload["'][^>]*>\s*/gi,
26
+ '',
27
+ )
28
+ }
29
+ return out
30
+ },
31
+ }
32
+ }
33
+
11
34
  export default defineConfig(({ mode }) => {
12
35
  const env = loadEnv(mode, path.resolve(__dirname, 'config/env'), '')
13
36
 
37
+ // 与 iot-ai-glasses 一致:由 VITE_PUBLIC_BASE 控制;未配置时默认 ./,便于 dist 下直接打开 index.html(file://)
14
38
  const rawPublicBase = (env.VITE_PUBLIC_BASE ?? '').trim()
15
39
  const base =
16
40
  mode === 'development'
@@ -23,8 +47,27 @@ export default defineConfig(({ mode }) => {
23
47
  : `${rawPublicBase}/`
24
48
  : './'
25
49
 
50
+ /** 相对路径构建时仅输出 legacy 包,便于 file:// 直接打开 dist/index.html */
51
+ const legacyOnlyForFileProtocol =
52
+ mode !== 'development' && (base === './' || base === '.')
53
+
26
54
  return {
27
- plugins: [vue()],
55
+ plugins: [
56
+ vue(),
57
+ legacy({
58
+ targets: [
59
+ '> 0%',
60
+ 'Chrome > 4',
61
+ 'Android >= 4',
62
+ 'IOS >= 7',
63
+ 'not ie <= 6',
64
+ 'Firefox ESR',
65
+ ],
66
+ renderLegacyChunks: true,
67
+ renderModernChunks: !legacyOnlyForFileProtocol,
68
+ }),
69
+ distHtmlPostProcess({ removeModulePreload: legacyOnlyForFileProtocol }),
70
+ ],
28
71
  envDir: path.resolve(__dirname, 'config/env'),
29
72
  resolve: {
30
73
  alias: [
@@ -48,6 +91,9 @@ export default defineConfig(({ mode }) => {
48
91
  ],
49
92
  },
50
93
  base,
94
+ build: {
95
+ cssCodeSplit: !legacyOnlyForFileProtocol,
96
+ },
51
97
  server: {
52
98
  host: true,
53
99
  port: 5174,
@@ -1,2 +0,0 @@
1
- # monorepo 内 dev:scaffold 预览标题(不会复制到脚手架生成项目)
2
- VITE_APP_TITLE=脚手架预览