@roki-h5/create-roki-app 0.1.10 → 0.1.11
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roki-h5/scaffold-template",
|
|
3
3
|
"private": true,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.7",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite --mode development",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@roki-h5/ui": "workspace:*",
|
|
16
|
-
"@vitejs/plugin-legacy": "
|
|
16
|
+
"@vitejs/plugin-legacy": "8.0.1",
|
|
17
17
|
"axios": "^1.7.9",
|
|
18
18
|
"event-source-polyfill": "^1.0.31",
|
|
19
19
|
"pinia": "^2.3.0",
|
|
@@ -33,12 +33,12 @@ function setupWebViewJavascriptBridge(
|
|
|
33
33
|
window.WVJBCallbacks = [callback]
|
|
34
34
|
|
|
35
35
|
const { iPhone, iPad, iPod } = browser.versions
|
|
36
|
-
// file://
|
|
37
|
-
|
|
36
|
+
// file:// 本地预览勿注入 bridge iframe,避免桌面浏览器报跨域安全错误
|
|
37
|
+
if (
|
|
38
|
+
(iPhone || iPad || iPod) &&
|
|
38
39
|
typeof location !== 'undefined' &&
|
|
39
|
-
location.protocol !== 'file:'
|
|
40
|
-
|
|
41
|
-
if (canUseIosBridgeIframe) {
|
|
40
|
+
location.protocol !== 'file:'
|
|
41
|
+
) {
|
|
42
42
|
const WVJBIframe = document.createElement('iframe')
|
|
43
43
|
WVJBIframe.style.display = 'none'
|
|
44
44
|
WVJBIframe.src = 'https://__bridge_loaded__'
|
|
@@ -5,8 +5,8 @@ import Home from '@/views/home/index.vue'
|
|
|
5
5
|
const HOME_TITLE_FALLBACK = '燃气热水器'
|
|
6
6
|
|
|
7
7
|
const router = createRouter({
|
|
8
|
-
//
|
|
9
|
-
history: createWebHashHistory(),
|
|
8
|
+
// 与 iot-water-heater5.0 一致:hash 路由,dist 下直接打开 index.html / file:// 可用
|
|
9
|
+
history: createWebHashHistory(import.meta.env.BASE_URL),
|
|
10
10
|
routes: [
|
|
11
11
|
{
|
|
12
12
|
path: '/',
|
|
@@ -9,7 +9,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
|
9
9
|
const monorepoUiDir = path.resolve(__dirname, '../../../ui')
|
|
10
10
|
const isMonorepoDev = fs.existsSync(path.join(monorepoUiDir, 'package.json'))
|
|
11
11
|
|
|
12
|
-
/** file://
|
|
12
|
+
/** file:// 下:去掉 crossorigin;仅 legacy 时再去掉 modulepreload(与 plugin-legacy 文档一致) */
|
|
13
13
|
function distHtmlPostProcess({ removeModulePreload = false } = {}) {
|
|
14
14
|
return {
|
|
15
15
|
name: 'dist-html-post-process',
|
|
@@ -34,7 +34,7 @@ function distHtmlPostProcess({ removeModulePreload = false } = {}) {
|
|
|
34
34
|
export default defineConfig(({ mode }) => {
|
|
35
35
|
const env = loadEnv(mode, path.resolve(__dirname, 'config/env'), '')
|
|
36
36
|
|
|
37
|
-
// 与 iot-
|
|
37
|
+
// 与 iot-water-heater5.0 一致:由 VITE_PUBLIC_BASE 控制;未配置时默认 ./,便于 dist 下直接打开 index.html(file://)
|
|
38
38
|
const rawPublicBase = (env.VITE_PUBLIC_BASE ?? '').trim()
|
|
39
39
|
const base =
|
|
40
40
|
mode === 'development'
|
|
@@ -47,25 +47,49 @@ export default defineConfig(({ mode }) => {
|
|
|
47
47
|
: `${rawPublicBase}/`
|
|
48
48
|
: './'
|
|
49
49
|
|
|
50
|
-
/** 相对路径构建时仅输出 legacy 包,便于 file:// 直接打开 dist/index.html */
|
|
51
50
|
const legacyOnlyForFileProtocol =
|
|
52
51
|
mode !== 'development' && (base === './' || base === '.')
|
|
53
52
|
|
|
53
|
+
const publicBase = (env.VITE_PUBLIC_BASE || '').trim()
|
|
54
|
+
const withTrailingSlash =
|
|
55
|
+
publicBase.startsWith('/') && publicBase.length > 1
|
|
56
|
+
? publicBase.endsWith('/')
|
|
57
|
+
? publicBase
|
|
58
|
+
: `${publicBase}/`
|
|
59
|
+
: ''
|
|
60
|
+
const pathWithoutTrailingSlash = withTrailingSlash.replace(/\/+$/, '')
|
|
61
|
+
const trailingSlashRedirect =
|
|
62
|
+
pathWithoutTrailingSlash && pathWithoutTrailingSlash !== '/'
|
|
63
|
+
? {
|
|
64
|
+
name: 'ensure-subpath-trailing-slash',
|
|
65
|
+
transformIndexHtml: {
|
|
66
|
+
order: 'pre' as const,
|
|
67
|
+
handler(html: string) {
|
|
68
|
+
const noTrail = JSON.stringify(pathWithoutTrailingSlash)
|
|
69
|
+
const withSlash = JSON.stringify(withTrailingSlash)
|
|
70
|
+
const snippet = `<script>(function(){var p=location.pathname;if(p===${noTrail})location.replace(location.origin+${withSlash}+location.search+location.hash);})();<\/script>`
|
|
71
|
+
return html.replace('<head>', `<head>${snippet}`)
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
: null
|
|
76
|
+
|
|
54
77
|
return {
|
|
55
78
|
plugins: [
|
|
56
79
|
vue(),
|
|
57
80
|
legacy({
|
|
58
81
|
targets: [
|
|
59
|
-
'
|
|
60
|
-
'Chrome
|
|
61
|
-
'Android >=
|
|
82
|
+
'> 0%',
|
|
83
|
+
'Chrome > 4',
|
|
84
|
+
'Android >= 4',
|
|
85
|
+
'IOS >= 7',
|
|
86
|
+
'not ie <= 6',
|
|
87
|
+
'Firefox ESR',
|
|
62
88
|
],
|
|
63
89
|
renderLegacyChunks: true,
|
|
64
|
-
// 与调料机一致:不输出 type=module 现代包,避免 file:// / App 容器加载失败
|
|
65
90
|
renderModernChunks: !legacyOnlyForFileProtocol,
|
|
66
|
-
polyfills: true,
|
|
67
|
-
additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
|
|
68
91
|
}),
|
|
92
|
+
...(trailingSlashRedirect ? [trailingSlashRedirect] : []),
|
|
69
93
|
distHtmlPostProcess({ removeModulePreload: legacyOnlyForFileProtocol }),
|
|
70
94
|
],
|
|
71
95
|
envDir: path.resolve(__dirname, 'config/env'),
|
|
@@ -90,21 +114,6 @@ export default defineConfig(({ mode }) => {
|
|
|
90
114
|
: []),
|
|
91
115
|
],
|
|
92
116
|
},
|
|
93
|
-
base,
|
|
94
|
-
build: {
|
|
95
|
-
assetsInlineLimit: 10240,
|
|
96
|
-
rollupOptions: legacyOnlyForFileProtocol
|
|
97
|
-
? {
|
|
98
|
-
output: {
|
|
99
|
-
format: 'iife',
|
|
100
|
-
inlineDynamicImports: true,
|
|
101
|
-
chunkFileNames: 'assets/[name]-[hash].js',
|
|
102
|
-
entryFileNames: 'assets/[name]-[hash].js',
|
|
103
|
-
assetFileNames: 'assets/[name]-[hash].[ext]',
|
|
104
|
-
},
|
|
105
|
-
}
|
|
106
|
-
: undefined,
|
|
107
|
-
},
|
|
108
117
|
server: {
|
|
109
118
|
host: true,
|
|
110
119
|
port: 5174,
|
|
@@ -117,5 +126,28 @@ export default defineConfig(({ mode }) => {
|
|
|
117
126
|
},
|
|
118
127
|
},
|
|
119
128
|
},
|
|
129
|
+
base,
|
|
130
|
+
build: {
|
|
131
|
+
// legacy-only 时 index 上 link 的 CSS 很少;关闭拆分,避免首页/懒路由样式未注入导致「样式丢失」
|
|
132
|
+
cssCodeSplit: false,
|
|
133
|
+
outDir: 'dist',
|
|
134
|
+
assetsDir: 'static',
|
|
135
|
+
assetsInlineLimit: 10240,
|
|
136
|
+
sourcemap: false,
|
|
137
|
+
chunkSizeWarningLimit: 2500,
|
|
138
|
+
rollupOptions: {
|
|
139
|
+
output: {
|
|
140
|
+
chunkFileNames: 'static/js/[name]-[hash].js',
|
|
141
|
+
entryFileNames: 'static/js/[name]-[hash].js',
|
|
142
|
+
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
minify: 'esbuild',
|
|
146
|
+
esbuild: {
|
|
147
|
+
drop: mode === 'production' ? ['console', 'debugger'] : [],
|
|
148
|
+
legalComments: 'none',
|
|
149
|
+
charset: 'ascii',
|
|
150
|
+
},
|
|
151
|
+
},
|
|
120
152
|
}
|
|
121
153
|
})
|